cocoa – 核心动画……循环动画?

前端之家收集整理的这篇文章主要介绍了cocoa – 核心动画……循环动画?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
要尽可能简单地说出我的问题,有没有办法创建一个核心动画序列来反复重复直到停止?

具体来说,我正在创建一个自定义类,我希望有一个-start和-stop方法,它会使它产生脉动.为脉冲编写动画代码不是问题,而是如何使其重复?

提前感谢您的任何答案!

解决方法

根据 the documentation,你可以通过创建一个极大的repeatCount动画来实现它(代码摘自我链接到的文档):
// 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询问如何停止动画.从文档中的next paragraph开始:

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.

原文链接:https://www.f2er.com/iOS/332975.html

猜你在找的iOS相关文章