我有一個相當好奇的問題。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