我有一个相当好奇的问题。UIView图层的animationForKey:始终为零
我认为我用CAKeyframeAnimation
进行动画制作。然而,动画按预期工作,一旦代理的animationDidStop:finished
方法被触发,与图层的animationForKey:
方法一起检查时,与该视图相关联的图层总是返回nil
。
这里的问题的说明:
// 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;
}
控制器
在其他地方,我有animationDidStop:finished:
方法定义如下:
- (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
}
}
为什么if块永远不会计算为真?为什么[someView.layer animationForKey:@"positionAnimation"]
总是nil
?此外,stringValue
具有正确的数据,但数组也是nil
。
我看到这个[说明](http://stackoverflow.com/questions/1255086/how-to-identify-caanimation-within-the-animationdidstop-delegate/5010291#5010291 );谁能证实这个理论 - 请吗? – haroldcampbell 2011-04-13 08:11:07