CAShapeLayer shadowPath animation. How to prevent shadow fill on animation completion?
<p>I'm creating a random <code>UIBezierPath</code>, setting the path to a <code>CAShapeLayer</code>'s <code>.path</code> property, and then animating the <code>CAShapeLayer</code>'s stroke like so:</p>

<pre><code>    // Get a path
    let path = createBezierPath()

    // Shape layer properties
    let color = randomCGColor() // Color of path and shadow
    let lineWidth = CGFloat(arc4random_uniform(50) + 11) // Width of line and shadow radius
    shapeLayer.path = path.CGPath
    shapeLayer.lineJoin = kCALineJoinRound
    shapeLayer.lineCap = kCALineCapRound
    shapeLayer.strokeColor = color
    shapeLayer.lineWidth = lineWidth
    shapeLayer.fillColor = UIColor.clearColor().CGColor
    // Shape layer shadow properties
    shapeLayer.shadowPath = path.CGPath
    shapeLayer.shadowColor = color
    shapeLayer.shadowOffset = CGSizeZero
    shapeLayer.shadowRadius = lineWidth
    shapeLayer.shadowOpacity = 1.0

    // Add shape layer
    self.layer.addSublayer(shapeLayer)

    // Stroke path animation
    let pathAnimation: CABasicAnimation = CABasicAnimation(keyPath: "strokeEnd")
    pathAnimation.fromValue = 0.0
    pathAnimation.toValue = 1.0

    // Shadow path animation
    let shadowPathAnimation: CABasicAnimation = CABasicAnimation(keyPath: "shadowPath")
    shadowPathAnimation.fromValue = 0.0
    shadowPathAnimation.toValue = path.CGPath

    // Animation group
    let animationGroup = CAAnimationGroup()
    animationGroup.duration = 5.0
    animationGroup.animations = [pathAnimation, shadowPathAnimation]

    shapeLayer.addAnimation(animationGroup, forKey: "allMyAnimations")
</code></pre>

<p>The issue is, once the animation completes the shadow is applied to the entire shape. I'd like the shadow to just be applied to the <code>CAShapeLayer</code>'s stroke. <strong>How can I prevent the shadow from applying to the entire shape after the animation completes?</strong> </p>

<p>Here's an example of the issue I'm referring to:</p>

<p><a href="https://i.stack.imgur.com/KCbQt.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KCbQt.gif" alt="enter image description here"></a></p>