애니메이션이 시작되면 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 is KVO 준수? – e1985