2010-10-11 66 views
1

我有5個不同的動畫,動畫然後一個接一個消失。有沒有辦法將它們放在一個無限循環中,以便動畫#1開始和結束,然後動畫#2開始和結束等等。?整個過程會在無限循環中重複。無限循環上的動畫

我在延遲單獨的塊中有動畫。我猜測有這樣做的更好方法。這是我現在擁有的:

-(void) firstAnimation { 

     [UIView beginAnimations:@"Fade Out Image" context:nil]; 
     [UIView setAnimationDelegate:self]; 
     [UIView setAnimationDelay:40]; 
     [UIView setAnimationRepeatCount:30]; 
     [UIView setAnimationRepeatAutoreverses:YES]; 
     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
     theImage.alpha = 1; 
     theImage.alpha = 0.1; 

     [UIView commitAnimations]; 

     [self secondAnimation]; 

} 

-(void) secondAnimation { 

     tapImage2.hidden = NO; 

     [UIView beginAnimations:@"Fade Out Image" context:nil]; 
     [UIView setAnimationDelegate:self]; 
     [UIView setAnimationDelay:53]; 
     [UIView setAnimationRepeatCount:29]; 
     [UIView setAnimationRepeatAutoreverses:YES]; 
     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
     theImage2.alpha = 1; 
     theImage2.alpha = 0.1;  

     [UIView commitAnimations]; 

    [self thirdAnimation]; 

} 

然後繼續5動畫。謝謝你的幫助。

回答

8

不是使用延遲,而是設置動畫委託並創建動畫完成方法。我注意到你已經設置了委託。

[UIView setAnimationDelegate:self]; 
[UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)]; 

- (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context { 
    //Start next animation based on the animationID of the last one... 
} 
+0

謝謝。這是一個更好的方法。 – hanumanDev 2010-10-11 20:04:03