iOS UIView动画取消不起作用

Joh*_*ohn 1 iphone objective-c uiviewanimation ios ios7

我有两个图像mosha1和mosha2.我通过UIView动画将它们从某个位置移动到另一个点(206,89).现在我希望如果用户在移动时触摸任何图像,那么该图像的移动将在那里停止.所以我设置了停止动画运动的代码:

[mosha1.layer removeAllAnimations];
Run Code Online (Sandbox Code Playgroud)

此方法调用会停止图像的移动,但是然后它会显示在点(206,89)中.但它应该出现在用户触摸的确切位置.怎么解决这个?

UIView动画方法:

-(void)moshaMoveUp: (UIImageView *)mosha {

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:3.0];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelegate:self];
mosha.center = CGPointMake(206, 89);
[UIView commitAnimations];

}
Run Code Online (Sandbox Code Playgroud)

Kru*_*lur 5

这样做的原因是动画如何与不同的层一起工作.在您开始动画的那一刻,您的对象在逻辑上立即就在目的地.但是,有一个表示层显示对象向目的地移动.因此,如果要停止对象,则需要从其表示层获取其当前位置UIView,将其分配给视图的位置,然后删除动画,并且您的对象应该在正确的位置.