重复beginAnimations——所有动画
我正在通过淡入和淡出 4 个不同的图像来制作一个简单的图像旋转器。它的效果很好,直到最后,当我想要重复所有四个动画时。
我已经尝试过重复计数,但这仅适用于该特定动画。如何创建一个完整的循环?
我的代码如下。提前致谢!
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:slideshow cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:3];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationDelay:3];
imageOne.alpha = 0;
imageTwo.alpha = 1;
[UIView setAnimationDelay:6];
imageTwo.alpha = 0;
imageThree.alpha = 1;
[UIView setAnimationDelay:9];
imageThree.alpha = 0;
imageFour.alpha = 1;
[UIView commitAnimations];
I'm making a simple image rotator by fading in and out 4 different images. It works great, until the end, when I want all four animations to repeat.
I've tried the repeat count, but that will only apply to that one specific animation. How do I create an entire loop?
My code is below. Thanks in advance!
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:slideshow cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:3];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationDelay:3];
imageOne.alpha = 0;
imageTwo.alpha = 1;
[UIView setAnimationDelay:6];
imageTwo.alpha = 0;
imageThree.alpha = 1;
[UIView setAnimationDelay:9];
imageThree.alpha = 0;
imageFour.alpha = 1;
[UIView commitAnimations];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以首先为动画命名,而不是
beginAnimations:nil
,而是输入beginAnimations: @"Button Animations"
或类似的内容。另外,您应该将动画的委托设置为 self。这可以通过将以下代码行添加到动画块中来完成:然后,您可以将整个动画块放入它自己的类方法中(在视图控制器中)。我们称之为 doAnimation。这只是为了安全措施。您应该做的下一件事是在视图控制器中实现此委托函数:
因此这几乎可以确保您的动画会重复。如果这个方法不起作用,请告诉我,我没有测试过。但我认为它会起作用。
You can start by putting a name to your animations so instead of
beginAnimations:nil
, you'd putbeginAnimations: @"Button Animations"
or something like that. Also, you should set the delegate of the animation to self. This can be done by adding the following line of code into your animation block:Then you can put this whole entire animation block into a class method of it's own (in your view controller). Lets call it doAnimation. This is just for safe measure. the next thing you should do is implement this delegate function in your view controller:
So pretty much this will ensure that your animations will repeat. If this method doesn't work, let me know, I didn't test it. But I think it'll work.