2016-02-01 79 views
0

我從來沒有遇到過這個問題。我的animationDidStop方法在動畫實際完成之前被調用。 animationDidStart被首先調用,但之後立即調用animationDidStop。我嘗試使用動畫完成塊來處理這個問題,但它仍然立即完成動畫。有人跑過這個嗎?我真的可以使用一些幫助。謝謝。animationDidStop方法立即調用

- 詹姆斯

CODE:

-(void) runAnimation { 

//Create an animation that rotates the tile 

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; 
[animation setDuration:6]; 
[animation setFromValue:[NSNumber numberWithFloat:0]]; 
[animation setToValue:[NSNumber numberWithFloat:0.5*M_PI]]; 
[animation setDelegate:self]; 
animation.fillMode = kCAFillModeForwards; 
animation.removedOnCompletion = NO; 

[[self.view viewWithTag:100].layer addAnimation:animation forKey:@"solutionRotate"]; 

} 

-(void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag 
{ 

     if (theAnimation == [[self.view viewWithTag:100].layer animationForKey:@"solutionRotate"]){ 

      //test 
      NSLog (@"test"); 

    } 

} 
+0

您的代碼示例中是否存在錯誤?添加「animateStuff」而不是「動畫」 –

+0

您是否嘗試過使用CATransaction完成塊? –

回答

2

如果該層沒有任何層樹則因爲沒有什麼實際在屏幕上的動畫,動畫將立即結束的一部分。確保將動畫視圖添加到可見視圖層次結構中。

相關問題