How to remove a layer when its animation completes?
animation, caanimation, calayer, ios, iphone
Solution
When you create the animation and set the delegate, just pass the CALayer you want to remove with your animation.
As for removing all the animations, you have two options:
- You can check your CALayer's animationKeys for any existing animations.
- You can use a CAAnimationGroup and group all your animations together.
Problem
I am making an iOS App. I have several `CALayer` objects that eventually will be deleted by a (shrinking) animation. When the animation is completed, and `animationDidStop:finished` is invoked, I would like to remove the `CALayer` object from the super view and delete it. - But how can I get the `CALayer` object in `animationDidStop:finished`? I would have guessed that the `CAanimation`-object had a pointer to the layer, but I can't find it in the doc. - Is there a better way to handle the issue? (Actually, I have several animation objects added to the same layer, and, ideally, I would like to remove the layer only when the last animation completes)