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

问题描述

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

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:

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

08-23 09:23