Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Infinite CABasicAnimation stops

Tags:

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?

like image 384
pinki Avatar asked Nov 21 '12 20:11

pinki


1 Answers

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.

like image 81
dispute Avatar answered Oct 20 '22 05:10

dispute