2012-10-30 50 views
0

可能重复:
Cancel a UIView animation?iOS的 - 如何停止的UIView动画在特定的框架

我需要停止UIView的动画。我知道我可以使用[object.layer removeAllAnimations];,但这并不能阻止动画,而是“跳过”它。因此,如果我的原创动画是:

[UIView animateWithDuration:8.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^ (void) { 
     [ingredient setFrame:CGRectMake(20, 200, 34, 45)]; 
    } completion:^ (BOOL finished) { 
     NSLog(@"Completed"); 
    }]; 

如果动画已完成,对象成分将具有该帧。相反,我希望对象停止在特定点,没有动画完成。

+0

如果关闭设备,所有动画将停止。 – 2012-10-30 14:01:26

+0

[取消UIView动画?](http://stackoverflow.com/questions/554997/cancel-a-uiview-animation)和[如何停止UIView动画](http://stackoverflow.com/问题/ 7204602/how-to-stop-an-uiview-animation) – 2012-10-30 14:02:35

+1

不是重复的,这个问题是关于'暂停'一个动画,而不是取消它。 – WDUK

回答

1

如果要暂停,但不打算重新开始,尝试:

CALayer *objectPresentationLayer = [object.layer presentationLayer]; 
object.layer.transform = objectPresentationLayer.transform; 
[object.layer removeAllAnimations]; 

如果要暂停和恢复动画,从苹果Q &一个检查了这一点: https://developer.apple.com/library/ios/#qa/qa2009/qa1673.html

+0

这似乎将动画移动到它在ios 9上的完成状态? – tommybananas

+0

也没有为我工作,但'progressView.layer.frame = progressView.layer.presentation()!. frame'确实工作 – kgaidis