This is the animation I want to achieve: a tick draws in, wait 1 sec and then draw out.
- strokeStart = 0.0 strokeEnd = 0.0
- strokeStart = 0.0 strokeEnd = 1.0
- strokeStart = 1.0 strokeEnd = 1.0
The first animation is working good. Then in the delegate callback I set up the new animation with 1 sec delay in beginTime.
But what actually happens is that an implicit animation plays first I guess becuase of setting tickLayer's strokeStart to 1.0. And after 1 sec the other animation plays as well.
I have no idea why is this happening. I set the key correctly when adding the animation.
func animateTick() {
...
tickLayer.strokeStart = 0.0
tickLayer.strokeEnd = 1.0
layer.addSublayer(tickLayer)
let inAnimation = CABasicAnimation(keyPath: "strokeEnd")
inAnimation.fromValue = 0.0
inAnimation.toValue = 1.0
inAnimation.duration = 0.3
inAnimation.delegate = self
tickLayer.addAnimation(inAnimation, forKey: "strokeEnd")
}
override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
let now = tickLayer.convertTime(CACurrentMediaTime(), fromLayer: nil)
tickLayer.strokeStart = 1.0
let outAnimation = CABasicAnimation(keyPath: "strokeStart")
outAnimation.fromValue = 0.0
outAnimation.toValue = 1.0
outAnimation.duration = 0.5
outAnimation.beginTime = now + 1.0
tickLayer.addAnimation(outAnimation, forKey: "strokeStart")
}