动画 CAShapeLayer 路径变化
Animate CAShapeLayer path change
我正在尝试像这样对 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
从旧值更改为新值的动画?
上面的代码现在是这样的:
不要为路径设置动画。配置整个路径,然后设置 strokeEnd
— 假设它是 0
,这样用户什么也看不到。现在,每次您想要进行更改时,将当前的 strokeEnd
更改为新的 strokeEnd
。路径似乎会进一步绕曲线延伸。
我正在尝试像这样对 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
从旧值更改为新值的动画?
上面的代码现在是这样的:
不要为路径设置动画。配置整个路径,然后设置 strokeEnd
— 假设它是 0
,这样用户什么也看不到。现在,每次您想要进行更改时,将当前的 strokeEnd
更改为新的 strokeEnd
。路径似乎会进一步绕曲线延伸。