2013-08-07 79 views
2

我想安排一系列在整個屏幕上爲動畫介紹文字生成動畫的動畫。完成後的最後一個動畫應該啓動應該運行遊戲的遊戲刻度邏輯。UIView animateWithDuration不尊重延遲

由於某種原因,一切都馬上發生。任何人都可以闡明爲什麼會發生這種情況或更好的選擇?

[self.view bringSubviewToFront:_ViewIntroSeconds]; 

[UIView animateWithDuration:0.4 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut 
       animations:^(void) { 
        [_IntroLabel1 setAlpha:1]; 
       } 
       completion:^(BOOL finished){ 
       }]; 

[UIView animateWithDuration:0.4 delay:3.0 options:UIViewAnimationOptionCurveEaseInOut 
       animations:^(void) { 
        [_IntroLabel2 setAlpha:1]; 
        [_IntroLabel1 setAlpha:0]; 
        [_IntroLabel1 setCenter:CGPointMake(0, _IntroLabel1.center.y)]; 
       } 
       completion:^(BOOL finished){ 
       }]; 

[UIView animateWithDuration:0.4 delay:5.0 options:UIViewAnimationOptionCurveEaseInOut 
       animations:^(void) { 
        [_IntroLabel3 setAlpha:1]; 
        [_IntroLabel2 setAlpha:0]; 
        [_IntroLabel2 setCenter:CGPointMake(0, _IntroLabel2.center.y)]; 
       } 
       completion:^(BOOL finished){ 
        [self updateGame]; 
        [self updateClock]; 

        [_ViewIntroSeconds setAlpha:0]; 
       }]; 

回答

3

我的建議是設置delay爲0,並將隨後的UIView動畫塊在前面animateWithDuration語句completion塊:

[UIView animateWithDuration:0.4 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut 
       animations:^(void) { 
        [_IntroLabel1 setAlpha:1]; 
       } 
       completion:^(BOOL finished){ 
        [UIView animateWithDuration:0.4 delay:2.6 options:UIViewAnimationOptionCurveEaseInOut 
             animations:^(void) { 
              [_IntroLabel2 setAlpha:1]; 
              [_IntroLabel1 setAlpha:0]; 
              [_IntroLabel1 setCenter:CGPointMake(0, _IntroLabel1.center.y)]; 
             } 
             completion:^(BOOL finished){ 
              [UIView animateWithDuration:0.4 delay:1.6 options:UIViewAnimationOptionCurveEaseInOut 
                  animations:^(void) { 
                   [_IntroLabel3 setAlpha:1]; 
                   [_IntroLabel2 setAlpha:0]; 
                   [_IntroLabel2 setCenter:CGPointMake(0, _IntroLabel2.center.y)]; 
                  } 
                  completion:^(BOOL finished){ 
                   [self updateGame]; 
                   [self updateClock]; 

                   [_ViewIntroSeconds setAlpha:0]; 
                  }]; 
             }]; 
       }]; 

這會給你想要的效果。

編輯:這是發生的原因是,UIView animateWithDuration塊開始動畫,並繼續執行下面的代碼,而動畫仍然有效。因此建議在完成塊中執行'下一個'動畫效果。否則,所有animateWithDuration請求將幾乎立即執行。

編輯2:我已經在塊中編輯了delay,分別給出0,3和5秒的「錯覺」。

+0

不錯的想法,但我希望動畫持續時間和下一個動畫之間的延遲有所不同 – Chris

+0

然後在相應的'animateWithDuration'塊中修改'delay'。請注意,「延遲」是累積的。如果將塊中的延遲設置爲1秒,2秒和3秒,則它們將在以下時間調用:1,3和6秒。 – n00bProgrammer

+0

很好,謝謝! – Chris

相關問題