【发布时间】:2014-11-24 20:37:36
【问题描述】:
我已经启动了一个新的 IOS 应用程序,但我的代码有问题。 关于应用程序的描述:在屏幕中间放置了一个圆圈,当我点击屏幕时,圆圈开始移动到我点击那里的点。 我已经对其进行了编程并且它的工作非常好,但是还有一件事:当我点击屏幕上的另一个点时,圆圈会在我点击后立即移动到第二个点! - 即使圆圈仍然移动到第一个点,他会立即开始移动到第二个点。 (这是最难的部分)。
这是我点击屏幕时的代码:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self.view.layer removeAllAnimations];
UITouch *myTouch = [[touches allObjects] objectAtIndex: 0];
CGPoint currentPos = [myTouch locationInView: self.view];
[UIView animateWithDuration:2
delay:0.0f
options:UIViewAnimationCurveEaseInOut | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
animations:^(){
circle.center = CGPointMake(currentPos.x, currentPos.y);
}
completion:^(BOOL finished){}];
}
请帮我解决这个问题。也许还有另一种方法可以让那个圆圈或在点击屏幕时动画化。
即使您可以提供代码,当我按下按钮时,圆圈会停止并且不会在我按下按钮时的位置向右移动 - (即使圆圈处于动画状态)所以它会是伟大的.. 谢谢。
【问题讨论】:
标签: objective-c animation uiview