I have a rather curious problem.
I have a view that I'm animating with a CAKeyframeAnimation
. The animation works as expected however, once the delegate's animationDidStop:finished
method is fired, the layer associated with the view always returns nil
when checked with the layer's animationForKey:
method.
Here's an illustration of the problem:
// This is in the view controller
- (void) doAnimation:(id)sender {
CAKeyframeAnimation *positionAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
[positionAnimation setValues:arrayOfPoint];
[positionAnimation setDuration:0.5];
// ViewController is the delegate and has the animationDidStop:finished: method
positionAnimation.delegate = self;
[positionAnimation setValue:@"I am Text" forKeyPath:@"positionAnimation"];
[someView.layer addAnimation:positionAnimation forKey:@"positionAnimation"];
someView.layer.position = newPosition;
}
Elsewhere in the controller, I have the animationDidStop:finished:
method defined as follows:
- (void) animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
NSArray *array = [someView.layer animationKeys];
NSString *stringValue = [anim valueForKey:@"positionAnimation"];
NSLog(@"valueForKey: %@", stringValue);
// Prints 'I am Text'
if(anim == [someView.layer animationForKey:@"positionAnimation"]) {
//THIS NEVER GET CALLED
}
}
Why does the if block never evaluate to True? Why is [someView.layer animationForKey:@"positionAnimation"]
开发者_JAVA百科 always nil
? Additionally, stringValue
has the correct data, but array is also nil
.
I can just guess, but maybe when method animationDidStop:finished:
is called your animation has already been removed from the layer. So [someView.layer animationForKey:@"positionAnimation"]
is nil.
Hope this'll help
精彩评论