Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Animation... cyclic animations?

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!

like image 313
cemulate Avatar asked Apr 24 '09 02:04

cemulate


1 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 invoking removeAnimationForKey:. You can stop all animations for a layer by sending the layer a removeAllAnimations message.

like image 104
Brian Campbell Avatar answered Sep 23 '22 07:09

Brian Campbell