I am making an iOS App. I have several CALayer objects that eventually will be deleted by a (shrinking) animation. When the animatio
One alternativ solution is to add a layer pointer to the animation object's dictionary, as follows
// in some define section
#define kAnimationRemoveLayer @"animationRemoveLayer"
then, in the animationDidStop,
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag{
CALayer *lay = [theAnimation valueForKey:kAnimationRemoveLayer];
if(lay){
[lay removeAllAnimations];
[lay removeFromSuperlayer];
}
}
and, finally, in the animation setup,
CALAyer * lay = ... ; BOOL shouldRemove = .... ; CABasicAnimation* anim = [CABasicAnimation animationWithKeyPath:@"position"]; anim.delegate = self; if (shouldRemove) [anim setValue:lay forKey:kAnimationRemoveLayer];