cem*_*ate 7 macos xcode cocoa core-animation
要尽可能简单地说出我的问题,有没有办法创建一个核心动画序列来反复重复直到停止?
具体来说,我正在制作一个自定义类,我希望有一个-start和-stop方法,它会使它产生脉动.为脉冲编写动画代码不是问题,而是如何使其重复?
提前感谢您的任何答案!
Bri*_*ell 15
根据文档,您可以通过创建一个非常大的动画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;
Run Code Online (Sandbox Code Playgroud)
编辑:OP询问如何停止动画.从文档的下一段开始:
您可以通过向
addAnimation:forKey:目标图层发送消息来启动显式动画,并将动画和标识符作为参数传递.一旦添加到目标图层,显式动画将一直运行,直到动画完成,或者从图层中删除.用于向图层添加动画的标识符也用于通过调用来停止它removeAnimationForKey:.您可以通过向图层发送removeAllAnimations消息来停止图层的所有动画 .
| 归档时间: |
|
| 查看次数: |
5574 次 |
| 最近记录: |