无限循环动画

发布于 2024-09-27 11:29:42 字数 1169 浏览 8 评论 0原文

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

网名女生简单气质 2024-10-04 11:29:42

设置动画委托并创建动画完成方法,而不是使用延迟。我注意到您已经设置了委托。

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

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...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文