How to not use isRemovedOnCompletion for CAAnimation in iOS
Issue #228
CAAnimation is about presentation layer, after animation completes, the view snaps back to its original state. If we want to keep the state after animation, then the wrong way is to use CAMediaTimingFillMode.forward
and isRemovedOnCompletion
Animation never ends
forwards
https://developer.apple.com/documentation/quartzcore/camediatimingfillmode/1427658-forwards
The receiver remains visible in its final state when the animation is completed.
isRemovedOnCompletion
https://developer.apple.com/documentation/quartzcore/caanimation/1412458-isremovedoncompletion
When true, the animation is removed from the target layer’s animations once its active duration has passed. Defaults to true.
1 | layer.fillMode = .forwards |
This is to tell the animation to never ends and keep its last presentation state. Wrong approach ❗️
Set final state before calling animation
The presentation state is just for animation, the source of truth lies in the layer itself. We need to set the final state before calling animation
1 | let animation = CABasicAnimation(keyPath: #keyPath(CAShapeLayer.strokeEnd)) |