多个UIView动画 [英] Multiple UIView Animations

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

问题描述

我试图一个接一个地执行多个UIView动画。但是,我听说,一个接一个地执行多个UIView动画是一种不好的做法,我应该改用Core Animation。我尝试了这段代码:

I am trying to perform multiple UIView animations one after the other. However, I've heard that it's bad practice to perform multiple UIView animations one after the other, and that I should instead use Core Animation. I tried this code:

//First Animation
[UIView beginAnimations:@"animation1" context:nil];
[UIView setAnimationDuration:2];
nwView.backgroundColor = [UIColor redColor];
nwView.frame = CGRectMake(CGRectGetMidX(screenSize),
                          CGRectGetMinY(screenSize),
                          width, 
                          height);
nwView.transform = CGAffineTransformMakeRotation(45.0f);
[UIView commitAnimations];

//Second Animation
[UIView beginAnimations:@"second animation" context:nil];
[UIView setAnimationDuration:2];

nwView.transform = CGAffineTransformMakeScale(0.5, 0.33);
nwView.backgroundColor = [UIColor purpleColor];

[UIView commitAnimations];

但是它只播放第二个动画。我知道这个问题类似于 UIView并存的两个动画,但是上下文略有不同。

But it only does the second animation. I know this question is similar to UIView two animations coexisting, but it has a slightly different context.

推荐答案

我认为使用UIView块连续制作2个动画没有任何问题。只需确保在第一个动画的completino块中开始第二个动画即可。

I don't think there is anything wrong with doing 2 animations in a row using UIView blocks. Just make sure you start your second animation in the completino block of the first animation.

如果没有块(您的示例),它将不起作用,因为您必须设置一个委托动画或设置setAnimationDidStopSelector的选择器。在那里,您应该开始第二个动画。

Without blocks (your example) it is not working as you will have to set a delegate to the animation or set a selector for setAnimationDidStopSelector. There you should start the second animation.

但是同样,使用块进行动画也没错(这是首选方式)。

But again, nothing wrong in doing animations with blocks (it is the preferred way).

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

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