【发布时间】:2017-02-21 21:10:44
【问题描述】:
我正在尝试对 CAShapeLayer 的 path 属性的更改进行动画处理,如下所示:
animatePathChange(for: progressLayer, toPath: progressPath.cgPath)
progressLayer.path = progressPath.cgPath
这是animatePathChange功能码:
func animatePathChange(for layer: CAShapeLayer, toPath: CGPath) {
let animation = CABasicAnimation(keyPath: "path")
animation.duration = 1.0
animation.fromValue = layer.path
animation.toValue = toPath
animation.timingFunction = CAMediaTimingFunction(name: "easeInEaseOut")
layer.add(animation, forKey: "path")
}
但最终的结果不是我想要的。如何实现将图层的 path 从旧值更改为新值的动画?
这就是上面代码现在的样子:
【问题讨论】:
-
你可以为图层的
strokeEnd设置动画而不是改变路径吗? -
这将为从头开始绘制的路径设置动画。我只想为路径上的新旧路径之间的差异设置动画。
-
我不知道为什么,但我对动画笑得很厉害。谢谢你的笑
标签: ios swift core-animation