UIView动画VS核心动画 [英] UIView animation VS core animation

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

问题描述

我正试图将视图滑动到视图中,并在它碰到屏幕的一侧时弹跳。

I'm trying to animate a view sliding into view and bouncing once it hits the side of the screen.

我正在做的幻灯片的一个基本示例如下:

A basic example of the slide I'm doing is as follows:

// The view is added with a rect making it off screen.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.07];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[theView setFrame:CGRectMake(-5, 0, theView.frame.size.width, theView.frame.size.height)];
[UIView commitAnimations];

然后在didStopSelector中调用更多动画来产生反弹效果。问题是,当多个视图被动画化时,反弹变得不稳定,而且,不再反弹。

More animations are then called in the didStopSelector to make the bounce effect. The problem is when more than one view is being animated, the bounce becomes jerky and, well, doesn't bounce anymore.

在我开始阅读之前如何做这在Core Animation中,(我知道它有点困难)我想知道使用Core Animation而不是UIView动画是否真的有优势。如果没有,我可以采取哪些措施来提高性能?

Before I start reading up on how to do this in Core Animation, (I understand it's a little more difficult) I'd like to know if there is actually an advantage using Core Animation rather than UIView animations. If not, is there something I can do to improve performance?

推荐答案

使用Core Animation(基于图层)你可以做很多事情事物,比如3D动画(在3d空间中嵌入你的视图)。

With Core Animation (Layer based) you can do much advanced things, like 3d animation (embedding your view in 3d space).

UiView动画虽然非常强大,但在你有足够的动画之前不应该是性能瓶颈。我只在你的代码中看到一个例子,它的持续时间非常短。实际上,您几乎可以立即设置帧属性(70 ms是14 fps)。您应该根据开始,结束和整个距离的持续时间来考虑UIView动画 - 通常为0.2秒到几秒。它不是为了一个接一个地发射一个微动画而设计的。

UiView animations are quite powerful though, and shouldn't be a performance bottleneck until you have plenty of them. I only see one example in your code, and its duration is extremely short. In fact, you are almost setting the frame property instantly (70 ms is 14 fps). You should think of UIView animation in terms of start, end, and the duration for the whole distance - which is typically 0.2 s to several seconds. It is not designed to to fire one micro animation after another.

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

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