我正试图动画path
CAShapeLayer
属性的更改,如下所示:
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
从旧值更改为新值的动画?
使用上面的代码现在看起来就像这样: