Found this answer here cocoabuilder , but basically you add the key value for CABasicAnimation for CALayer, which is being animated.
- (CABasicAnimation *)animationForLayer:(CALayer *)layer { CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"]; [animation setValue:layer forKey:@"animationLayer"]; [animation setDelegate:self]; return animation; }
Then specify it in the animationDidStop callback
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag { CALayer *layer = [anim valueForKey:@"animationLayer"]; if (layer) { NSLog(@"removed %@ (%@) from superview", layer, [layer name]); [layer removeFromSuperlayer]; } }
Nate potter
source share