【问题标题】:Animate CAShapeLayer path change动画 CAShapeLayer 路径变化
【发布时间】: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


【解决方案1】:

不要为路径设置动画。配置整个路径,然后设置strokeEnd——假设它是0,所以用户什么也看不到。现在,每次您想要进行更改时,将当前strokeEnd 更改为新strokeEnd 的动画。路径似乎会围绕曲线进一步延伸。

【讨论】:

  • 为什么我没想到这一点.. 非常感谢!
猜你喜欢
  • 1970-01-01
  • 2017-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多