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?
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?
Thanks in advance for any answers!
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;
edit: The OP asked how to stop the animation. From the next paragraph in the documentation:
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 invokingremoveAnimationForKey:
. You can stop all animations for a layer by sending the layer aremoveAllAnimations
message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With