- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想在动画开始时观察 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/
我正在尝试为音乐播放器构建进度 View 。总的来说,我对编程完全陌生,现在真的走进了死胡同。 我的进展顺利。我用媒体文件的值(值/持续时间)来制作“中风结束”动画,但中风结束只能到达圆的部分。不过,
这个问题在这里已经有了答案: addArc(withCenter) closing path (2 个答案) 关闭 3 年前。 我正在使用 CAShapeLayer 绘制一个圆圈,由于某种原因,笔画
我有一个 CAShapeLayer以正方形的形式,我设置了 width为 2.0f。 我想为其 strokeEnd 制作动画为此,我使用了 CABasicAnimation像这样: CABasicAn
我正在尝试制作一个类似于 Android Material 设计循环不确定事件指示器的自定义事件指示器。基本上我想画圆圈两次并删除它,但删除和绘制不会同时或速度发生。这是我目前所拥有的: let pr
我似乎无法从我的 CAShapeLayer 的 strokeEnd 属性中删除动画。 文档说该属性是可动画,但默认情况下不是动画,我无法查明问题所在。有什么建议在哪里看? 这是我的代码: class
这是我用来为我的 CAShapeLayer 设置动画的代码: _progressBarLayer.strokeEnd = CGFloat(_progressToDrawForProgress(prog
我有两层。 A 层 和B 层。 我正在将 A 层 的 strokeEnd 从某个值设置为某个新值的动画。我还需要同时更改 Layer B 上的某些内容,但这取决于 Layer A 在设置动画时 str
我有这段代码: let arcPath = UIBezierPath(ovalInRect: CGRectMake(0, 0, frame.width, frame.height))
我正在尝试实现与所附图片类似的效果,其中圆圈根据您的关卡进度进行动画处理,然后在动画路径的两端附加一个标签以显示获得的经验以及未绘制的部分圆圈以显示剩余的经验。我根据需要设置了圆圈动画,但无法想出使标
我的问题是关于跟踪 CAShapeLayer 的 strokeEnd 点坐标的可能性。 我有一个 UISlider,它生成一个介于 0 和 1 之间的变量。我从 CGMutablePathRef 创建
我试图描绘出我放置到 CAShapeLayer 中的路径的形状。在此函数中,points 数组中的点表示正多边形的顶点。但是,动画没有发生。它刚刚出现,完全生动。 代码如下: private func
我是一名优秀的程序员,十分优秀!