完成后未删除时如何重用CABasicAnimation? [英] How to reuse an CABasicAnimation when not removed after completion?

查看:139
本文介绍了完成后未删除时如何重用CABasicAnimation?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很多人都在谈论使用CABasicAnimation对象之后。

Lots of people are talking about keeping an CABasicAnimation object around after it has been used.

因此,通过设置


removedOnCompletion = NO

removedOnCompletion = NO

动画完成后,动画对象将保持附着在图层上。我该如何在不创建新的CABasicAnimation的情况下再次重新启动该动画?

the animation object keeps attached to the layer when the animation is complete. How would I re-launch this animation again without creating a new CABasicAnimation?

保持该对象的意义何在?我知道的唯一好处是,我们可以将removeOnCompletion = NO设置为kCAFillModeForwards,以便Core Animation不会将视觉表示恢复为CALayer中的模型值。

What's the point of keeping this object around? The only benefit I know is that we can set removedOnCompletion = NO and set kCAFillModeForwards so that Core Animation does not revert the visual representation back to the model values in the CALayer.

但是如何像每个人都在谈论的那样重新使用动画?

But how to re-use the animation, like everyone is talking about?

推荐答案

尝试一下:


  1. 使用 [layer addAnimation:myAnimation forKey:@ myKey]

要在以后获得对它的引用,请调用 [layer animationForKey:@ myKey]

To get a reference to it later, call [layer animationForKey:@"myKey"]

阅读 Apple提供的注释解释了如何暂停和恢复(重新启动)动画。

Read this note from Apple which explains how to pause and resume (restart) animations.

这篇关于完成后未删除时如何重用CABasicAnimation?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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