嗨,大家好我在这里很好。
而我有一个UIimageview
。
我知道UITouch
的坐标是什么。
现在我想要球(UIImageView
)朝它走。
我试图想办法做到这一点...
使用CGPoint
但我想不出任何办法,将工作正常
我怎样才能做到这一点? (我没有在互联网上找到答案)Xcode对象移动到手指即时新这里
- (void)viewDidLoad
{
[super viewDidLoad];
[self play];
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(play) userInfo:nil repeats:YES];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
ballvelocity = [touch locationInView:self.view];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
ballvelocity = [touch locationInView:self.view];
}
-(void) play{
[UIView animateWithDuration:3 animations:^{
ball.center = CGPointMake(ballvelocity.x, ballvelocity.y);
}];
}
请发表你试过什么。 Stack Overflow预计你会付出一些努力,我们会从那里帮助你。 – 2012-03-04 18:41:48