使用setAnimationDelay的Iphone顺序动画 [英] Iphone sequential animation with setAnimationDelay

查看:112
本文介绍了使用setAnimationDelay的Iphone顺序动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想链接动画事件。我编写的工作的应用程序有一个多选择测验。首先你选择你的多项选择答案。测验视图消失。然后一个标签(正确或不正确)淡入,然后淡出。最后,测验又回来了。事件由一个主viewController调用和处理。我知道我可以链接事件与setAnimationDelegate和setAnimationDidStopSelector,但我认为这将更容易和更清楚地简单地使用setAnimationDelay所以所有的动画有时间完成下一个动画之前。

I'm trying to chain animation events. The application I'm coding for work has a multiple choice quiz. First you pick your multiple choice answer. The quiz view fades away. Then a label ("correct" or "incorrect") fades in and then fades out. Finally the quiz fades back in again. The events are called and handled by a main viewController. I know I can chain events with the setAnimationDelegate and setAnimationDidStopSelector but I think it'll be easier and more clear to simply use setAnimationDelay so that all animations have time to finish before the next one fires.

我使这个函数存在于包含正确不正确标签的类中。

I made this function that exists in the class that holds the "correct" "incorrect" label.

- (void)showIncorrect:(float)duration withDelay:(float)delay{
labelView.text = @"Incorrect!";
labelView.textColor = [UIColor redColor];

[UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDelay:delay];
    [UIView setAnimationDuration:(duration/2)];
    self.alpha = 1.0;
[UIView commitAnimations];

[UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDelay:(duration/2+delay)];
    [UIView setAnimationDuration:(duration/2)];
    self.alpha = 0.0;
[UIView commitAnimations];

}

第一个动画块被忽略?我尝试嵌套一个动画块到另一个,这也不工作。

Can someone tell my why the first animation block is ignored? I've tried to nest one animation block into the other and this does not work either.

推荐答案

你实际上正在设置相关的价值,并告诉什么在屏幕上动画赶上这个新的现实。所以无论你在第一个动画块中设置的值是否被有效地忽略,因为你已经覆盖了事实alpha == 1的事实,alpha == 0。

When you animate this way, you're actually setting the relevant value immediately, and telling what's onscreen to animate to catch up to that new reality. So whatever value you set in the first animation block is being effectively ignored, because you've overwritten the fact that alpha == 1 by the fact that alpha == 0.

对于更复杂的动画,值得使用CoreAnimation构建和添加动画。这是一个更多的工作,但你得到更多的控制。

For doing more complex animations, it is worth building and adding the animations using CoreAnimation. It is a little more work, but you get lots more control.

在这种情况下,你想使用CAKeyframeAnimation的一个实例。你可能还想使用CABasicAnimation在新的测验视图中进行动画。您可以使用CAAnimationGroup来确保您添加的多个动画同步。

In this case, you want to use an instance of CAKeyframeAnimation. You'll probably also want to use a CABasicAnimation to animate in your new quiz view. You can use a CAAnimationGroup to make sure that multiple animations that you add are synchronized.

这篇关于使用setAnimationDelay的Iphone顺序动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆