Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reuse an CABasicAnimation when not removed after completion?

Lots of people are talking about keeping an CABasicAnimation object around after it has been used.

So by setting

removedOnCompletion = NO

the animation object keeps attached to the layer when the animation is complete. How would I re-launch this animation again without creating a new CABasicAnimation?

What's the point of keeping this object around? The only benefit I know is that we can set removedOnCompletion = NO and set kCAFillModeForwards so that Core Animation does not revert the visual representation back to the model values in the CALayer.

But how to re-use the animation, like everyone is talking about?

like image 532
Proud Member Avatar asked Jan 21 '11 11:01

Proud Member


1 Answers

Try this:

  1. Add the animation with a key using [layer addAnimation:myAnimation forKey:@"myKey"]

  2. To get a reference to it later, call [layer animationForKey:@"myKey"]

  3. Read this note from Apple which explains how to pause and resume (restart) animations.

like image 114
Martin Wickman Avatar answered Oct 04 '22 20:10

Martin Wickman