2010-10-13 109 views
1

我想要一個按鈕移動到一個座標,暫停,移動到另一個協調,暫停,然後再次移動。該過程應該無限重複。我現在所擁有的只是最後一步。動畫按鈕延遲 - iPhone

這是我迄今爲止(「發」是的UIButton名):

- (void) firstAnimation { 

     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:0.5]; 
     [UIView setAnimationDelay:5]; 
     [UIView setAnimationRepeatCount:-1]; 
     [UIView setAnimationRepeatAutoreverses:NO]; 

     CGPoint pos = mover.center; 
     pos.y = 200.f; 
     pos.x = 169.f; 
     mover.center = pos; 

     [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(firstAnimation:) userInfo:nil repeats:NO]; 
     pos.y = 100.f; 
     pos.x = 179.f; 
     mover.center = pos; 

     [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(firstAnimation:) userInfo:nil repeats:NO]; 
     pos.y = 160.f; 
     pos.x = 129.f; 
     mover.center = pos; 

     [UIView commitAnimations]; 

} 

感謝您的幫助

回答

1

如果你航運iOS4的獨家,我全力推薦使用塊和下面的方法:

[UIView animateWithDuration:kAnimationDuration 
         delay:kAnimationDelay 
        options:UIViewAnimationCurveEaseInOut 
       animations:^ { 
        // your animations here. 
       } 
       completion:^(BOOL finished) { 
        // what you want to do upon animation completion here. 
       }]; 

請注意,在完成塊你c另外還有一個動畫。實際上,您可以將三個動畫塊存儲爲塊變量,然後將它們傳遞到上面的方法中,以便一個接一個地執行,直到第三個動畫塊完成。然後只需重新啓動過程!

積木是你的朋友。

+0

感謝您的留言。我使用以下內容淡入淡出圖像。我將如何讓它重複無限? - (無效)firstAnimation { \t \t [UIView的animateWithDuration:2.0 \t \t \t \t \t \t \t \t \t \t動畫:^ { \t \t \t \t \t \t \t \t \t \t \t \t tapImage.alpha = 0.0 ; \t \t \t \t \t \t \t \t \t \t \t \t tapImage.alpha = 1.0; \t \t \t \t \t \t \t \t \t \t \t} \t \t 完成:^(BOOL完成){ \t \t \t \t \t \t \t \t \t \t \t \t [自secondAnimation]; }]; } – hanumanDev 2010-10-13 22:35:20

3

您不需要使用定時器,只需設置動畫代表自我實現動畫完成的方法。

見我的答案在這裏:

animations on infinite loop