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.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...