CAAnimation,快速恢复
我正在尝试使用 CAAnimation,并且像许多尝试 CAAnimation 的新手一样;完成后,该层将恢复到其原始状态。
关于如何解决这个问题的问题已经在这里问过几次了,答案是将以下代码添加到您的 CAAnimation 中。
animation.removedOnCompletion = NO;
虽然这可行,但根据 Apple 的 WWDC 视频讨论 CAAnimation,推荐的解决方案是:
// animating opacity
layer.opacity = newOpacityValue;
[layer addAnimation:animation forKey:@"opacity"];
所以我有兴趣知道这两者之间的主要区别是什么以及何时使用它们?
I'm experimenting with CAAnimation and like many new comers doing the CAAnimation; upon completion, the layer is reverted back to its original state.
The question on how to resolve this have asked few times here, and the answer is to add the following code to your CAAnimation.
animation.removedOnCompletion = NO;
While this works, but according to Apple's WWDC video discussing CAAnimation, the recommended solution would be:
// animating opacity
layer.opacity = newOpacityValue;
[layer addAnimation:animation forKey:@"opacity"];
So I'm interested to know what is the main difference between this two and when to use them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
显式动画实际上并不修改 CALayer 的属性。
他们只是修改 presentationLayer,这就是你实际看到的。动画完成后,您将看到 CALayer 与动画之前完全相同。
通过设置这样的值,
您可以确保动画值存储在模型中,因此即使从图层中删除动画,您的更改也会继续存在。
使用removedOnCompletion = YES不是一个持久的解决方案。每当您从图层中删除动画时,它都会恢复到旧状态。
Explicit animations do not actually modify the attributes of a CALayer.
They just modify the presentationLayer, this is what you actually see. When the animation is finished you will see the CALayer exactly the same as it was before the animation.
By setting the value like this
you make sure the animated values are stored in the model, so your changes will live on even when the animation is removed from the layer.
Using removedOnCompletion = YES is not a persistent solution. Whenever you remove animations from a layer it will restore to is old state.
您不需要“removedOnCompletion”标志。
您需要的是将不透明度设置为动画外部的新值 - 正如您的第二个示例。
使用“removedOnCompletion”不会释放您的动画对象 - 如果您有很多动画,则会耗尽您的内存。
You don't need the "removedOnCompletion" flag.
What you need is to set the opacity to the new value OUTSIDE the animation as well - as your second example.
using "removedOnCompletion" will not release your animation object - blowing up your memory if you have a lot of animations.