title: Animate CAShapeLayer path change
body: <p>I'm trying to animate change of <code>path</code> property of <code>CAShapeLayer</code> like this:</p>
  <pre><code>animatePathChange(for: progressLayer, toPath: progressPath.cgPath)
  progressLayer.path = progressPath.cgPath
  </code></pre>
  <p>And this is<code>animatePathChange</code>function code:</p>
  <pre><code>func animatePathChange(for layer: CAShapeLayer, toPath: CGPath) {
      let animation = CABasicAnimation(keyPath: &quot;path&quot;)
      animation.duration = 1.0
      animation.fromValue = layer.path
      animation.toValue = toPath
      animation.timingFunction = CAMediaTimingFunction(name: &quot;easeInEaseOut&quot;)
      layer.add(animation, forKey: &quot;path&quot;)
  }
  </code></pre>
  <p>But the end result is not what i want. How can i achieve animation that changes layer's <code>path</code> from old value to new?</p>
  <p>This is how it looks right now with the code above:</p>
  <p><a href="https://i.stack.imgur.com/tMdNe.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/tMdNe.gif" alt="Result" /></a></p>