核心动画...循环动画? [英] Core Animation... cyclic animations?

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

问题描述

为了尽可能简单地说出我的问题,有没有办法创建一个核心动画序列来重复一遍又一遍,直到停止?

To phrase my question as simply as possible, is there a way to create a core animation sequence to repeat over and over until a stop?

我做一个自定义类,我想有一个-start和-stop方法,将导致它脉动。

Specifically, I'm making a custom class that I want to have a -start and -stop method that will cause it to pulsate. Writing the animation code for the pulse is not the problem, rather, how to make it repetitive?

提前感谢任何答案!

推荐答案

根据文档,您可以通过创建一个非常大的 repeatCount 代码摘自我链接到的文档):

According to the documentation, you do it by creating an animation with an extremely large repeatCount (code excerpted from the documentation I linked to):

// create the animation that will handle the pulsing.
CABasicAnimation* pulseAnimation = [CABasicAnimation animation];

// over a one second duration, and run an infinite
// number of times
pulseAnimation.duration = 1.0;
pulseAnimation.repeatCount = HUGE_VALF;

// we want it to fade on, and fade off, so it needs to
// automatically autoreverse.. this causes the intensity
// input to go from 0 to 1 to 0
pulseAnimation.autoreverses = YES;

编辑:OP询问如何停止动画。从下一段

edit: The OP asked how to stop the animation. From the next paragraph in the documentation:


您通过
开始一个明确的动画,发送一个 addAnimation:forKey:消息
到目标层,传递
动画和标识符作为
参数。一旦添加到目标
层,显式动画将运行
,直到动画完成,或它
从图层中删除。用于向
一层添加动画的
标识符也用于通过
调用 removeAnimationForKey:来停止它。您
可以通过发送图层a
removeAllAnimations 消息来停止图层的所有动画。

You start an explicit animation by sending a addAnimation:forKey: message to the target layer, passing the animation and an identifier as parameters. Once added to the target layer the explicit animation will run until the animation completes, or it is removed from the layer. The identifier used to add an animation to a layer is also used to stop it by invoking removeAnimationForKey:. You can stop all animations for a layer by sending the layer a removeAllAnimations message.

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

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