可能是重复问题:
如何取消UIView动画?
我有以下动画,当我按下一个按钮时,我想停止它。你能告诉我怎么做吗?我无法弄清楚。谢谢。
-(void)animationLoop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
[UIView beginAnimations:@"Move randomly" context:nil];
[UIView setAnimationDuration:1];
// [UIView setAnimationBeginsFromCurrentState:NO];
CGFloat x = (CGFloat) (arc4random() % (int) self.bounds.size.width);
CGFloat y = (CGFloat) (arc4random() % (int) self.bounds.size.height);
CGPoint squarePostion = CGPointMake(x, y);
strechView.center = squarePostion;
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationLoop:finished:context:)];
[UIView commitAnimations];
}