I 've an infinite animation (rotating an image, type: CABasicAnimation
) in my UIView with
animation.repeatCount = HUGE_VALF;
When I push a new ViewController and go back to the initial ViewController with the animation containing View inside, the rotation stopped.
Even if I set up the animation again when the ViewController's viewWillAppear
method gets called, it won't rotate again.
What am I doing wrong?
Actually, there is a simple way to solve this
setting your animation to this:
Swift 3 version
animation.removedOnCompletion = false
Swift 4 version
animation.isRemovedOnCompletion = false
The layer itself isn't destroyed, when NavigationController is being pushed to another ViewController's view, because UINavigationController got viewControllers
property which will retain the original viewController and therefore its view and your animated layer.
It is this CABasicAnimation object destroyed when view removed from interface even though you set its repeatCount to infinite. So set the isRemovedOnCompletion
to false to keep it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With