animations on infinite loop

≯℡__Kan透↙ 提交于 2019-12-06 12:22:59

问题


I have 5 different animations that animate then disappear one after another. Is there a way to put them on an infinite loop so animation #1 begins and ends, then anim #2 begins and ends etc..? the whole process then would repeat on an infinite loop.

I have the animations in separate blocks on delays. I'm guessing that there is a better way of doing this. this is what I have at the moment:

-(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];

}

this then goes on for 5 animations. thanks for any help.


回答1:


Instead of using the delay, set the animation delegate and create an animation done method. I notice you are already setting the delegate.

[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...
}


来源:https://stackoverflow.com/questions/3909399/animations-on-infinite-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!