I saw How to define CAAnimation in the animationDidStop delegate? is an addition to it.
I cannot get this to work properly. I have an animation, and I would like to release a controller that was launched after the animation ended. Example: the controller moves from right → left, then frees itself.
Animation Definition:
NSValue *end = [NSValue valueWithCGPoint:CGPointMake(800, self.view.center.y)]; NSValue *start = [NSValue valueWithCGPoint:self.view.center]; CABasicAnimation *moveAnimation; moveAnimation = [CABasicAnimation animationWithKeyPath:@"position"]; moveAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; moveAnimation.duration = 0.45f; moveAnimation.fromValue = start; moveAnimation.toValue = end;
Inside the delegate method:
- (void) animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag { CAAnimation *check = [self.view.layer animationForKey:MOVING_OUT]; if (theAnimation == check) {
If you leave this code as it is, my controller will not receive dealloc'd (due to holding the call by animation). If I run [check release] , I get a message sent to deallocated instance .
Does anyone know what happened? Is there any other way to identify CAAnimation in the animationDidStop delegate WITHOUT specifying removedOnCompletion = NO ?
EDIT: Forgot to mention. Without indicating that removedOnCompletion = NO , animationForKey: will return NULL. Therefore, I cannot identify the animation.
Thanks!
mmilo source share