gpt4 book ai didi

cocoa - 核心动画...循环动画?

转载 作者:行者123 更新时间:2023-12-03 16:07:04 25 4
gpt4 key购买 nike

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

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

预先感谢您的回答!

最佳答案

根据the documentation ,您可以通过创建一个具有极大 repeatCount 的动画来实现此目的(代码摘 self 链接到的文档):

// 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.

关于cocoa - 核心动画...循环动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/784365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com