gpt4 book ai didi

ios - 观察 'strokeEnd'层动画事件

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:21:49 27 4
gpt4 key购买 nike

我想在动画开始时观察 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...
}

最佳答案

当动画像这样“飞行”时,您无法观察到动画属性的变化。该属性实际上设置为动画开始时的结束值。然后有一个“表示层”,位于 View 的常规层之上,动画发生在该层上。

最好的办法是设置一个 CADisplayLink 计时器(一个与屏幕刷新率同步的轻量级计时器)并查询表示层上的属性因为它动画(layer.presentationLayer.strokeEnd,在你的例子中。)

关于ios - 观察 'strokeEnd'层动画事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47824884/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com