0
votes

I have a CAShapeLayer, whose strokeEnd I occasionally update inside of an NSTimer loop. Works great, when I call:

myPathLayer.strokeEnd += 0.1

this path change automatically animates as I want it to. My question is, as this isn't a function call, there isn't a completion block. I'd like to perform another action once this animation completes. How can I achieve this?

2

2 Answers

1
votes

You can wrap in with a CATransaction to set a completion block for layer animations.

CATransaction.begin()
CATransaction.setCompletionBlock({self.myFunction()})
myPathLayer.strokeEnd += 0.1
CATransaction.commit()

Hopefully there is a better way, but this is how I've done it.

0
votes

You can use CAAnimation delegate method.

class Whatever: CAAnimationDelegate { ...

then

let animation = CABasicAnimation(keyPath: <your_key_path>)
...
animation.delegate = self

and use the delegate method:

func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {

     if flag { <do_what_you_need_to> }
}