2011-08-18 37 views
0

我需要在小鳥像素處出現鳥圖像的動畫,然後生長並移動到動畫的中點。之後,鳥縮回到小像素,但向前移動,直到達到終點。我需要這個動畫是可重複的。我用兩種動畫做到了這一點:第一種增加圖像並移動,在第二種動畫中完成,第二種縮小和移動。第一個動畫有重複選項,recond beginFromCurrentState。問題是從未被調用過的完整塊。我錯過了什麼,也許完整的塊不適用於可重複的動畫?這裏是我的代碼:如何做一個可重複的嵌套的UIView動畫?

[UIView animateWithDuration:4.0 delay:0 options:(UIViewAnimationCurveEaseIn | UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction) animations:^{ 
    self.bird1.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1, 1); 
    self.bird1.center = bird1MiddlePoint; 

} completion:^(BOOL finished){if (finished){ 

    NSLog(@"doesn't get called"); 
    [UIView animateWithDuration:4.0 delay:0 options:(UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction) animations:^{ 

     self.bird1.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.1, 0.1); 
     self.bird1.center = bird1EndPoint;} completion:^(BOOL finished){if (finished && !self.gameManager.isPlaying){ 

      [UIView setAnimationRepeatCount:0]; 
      [self.bird1 removeFromSuperview]; 

    }}];   
}}]; 

回答

4

如果父動畫無限期地重複,因爲你設置UIViewAnimationOptionRepeat,它不會打電話完成塊,因爲它永遠不會完成。就這麼簡單。

+0

如果完整的模塊甚至可以用於重複動畫,它會更合理;)因爲現在不可能嵌套內部動畫(至少使用UIView動畫) – Centurion

+1

我有一個叫CAKeyframeAnimation的朋友。我想你應該見他。 – MiguelB

+0

順便說一下,使用延遲選項對UIView動畫塊提供瞭解決方法,這樣就不必使用完成塊,但我不建議這樣做,尤其是如果您連續動畫製作相同的屬性。 – MiguelB