When the first strokeEnd animation is executed, and the second one starts, there is a kind of flash, meaning the part of the circle that was drawn until this point disappears, and then drawing starts from 0.
If you compare the settings of both drawAnimation and endDrawAnimation , you will see that they are identical, except for the beginTime . That is why you flicker. They both start at 0 and both end at 1. Since you did not specify the desired result, I can simply assume that you want endDrawAnimation have fromValue of 1.
let drawAnimation = CABasicAnimation(keyPath: "strokeEnd") drawAnimation.duration = duration / 2 drawAnimation.fromValue = 0 drawAnimation.toValue = 1 drawAnimation.isRemovedOnCompletion = false drawAnimation.fillMode = kCAFillModeForwards let endDrawAnimation = CABasicAnimation(keyPath: "strokeEnd") endDrawAnimation.beginTime = duration / 2 // Starts after the first animation and starts with 0 again. endDrawAnimation.duration = duration / 2 endDrawAnimation.fromValue = 0 endDrawAnimation.toValue = 1 endDrawAnimation.isRemovedOnCompletion = false endDrawAnimation.fillMode = kCAFillModeForwards
Suggestion for improvement
As far as I see, you want to create a keyframe animation, which means that you have predefined offsets at which the animation behavior changes (speed, value, etc.). You might want to use CAKeyframeAnimation .
I'm not sure what you know about this, but at the moment you have two animations running simultaneously on strokeStart :
eraseAnimation starting with 0.2 with a duration of 0.5 * durationendEraseAnimation starting with 0.5 * duration .
This means that the end of eraseAnimation ( 0.2 + 0.5 * duration ) is always greater than the beginning of endEraseAnimation ( 0.5 * duration )
Jens meder
source share