アニメーションが開始されたときにstrokeEndキーパスを確認したい。しかし、それはうまくいかない、どこがうまくいかなかったのだろうか?レイヤー 'strokeEnd'アニメーションイベントを観察する
- (void)addAnimation {
// do animation
CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
drawAnimation.duration = 3.f;
drawAnimation.repeatCount = 1.0;
drawAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
drawAnimation.toValue = [NSNumber numberWithFloat:0.5f];
drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
drawAnimation.fillMode = kCAFillModeForwards;
drawAnimation.removedOnCompletion = NO;
[self.progressLayer addAnimation:drawAnimation forKey:@"drawCircleAnimation"];
[self.progressLayer addObserver:self forKeyPath:@"strokeEnd" options:NSKeyValueObservingOptionNew context:NULL]; // 监听position
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
NSLog(@"change:%@",change);
// not called here...
}
違いがあるかどうかは分かりませんが、NULLの代わりに 'nil'としてコンテキストを指定してみてください。他の問題は表示されません。 – Skywalker
あなたは確かですかstrokeEndはKVOです準拠? – e1985