2012-10-30 52 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