2010-10-11 87 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