无限循环上的动画

时间:2010-10-11 19:41:35

标签: iphone objective-c core-animation infinite-loop

我有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个动画。谢谢你的帮助。

1 个答案:

答案 0 :(得分: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...
}
相关问题