Search code examples
ioscaanimationuiviewpropertyanimator

UIViewPropertyAnimator - simply stop all animations, rather than a specific one?


In UIViewPropertyAnimator, is there a way to just stop all UIViewPropertyAnimator animations?

Or perhaps simply get all current animations - then of course you could stop them all.

Can this be done?

Or do you really have to

  • (a) do only one per UIViewPropertyAnimator,

and,

  • (b) keep a reference to each of those?

Solution

  • Every animation has to have atleast one UIViewPropertyAnimator instance. In order to stop the animation, we have to explicitly call stopAnimation(_:) on the animator instance.

    A way would be to make a factory class to fetch UIViewPropertyAnimator instance and keep track of it in a set or array. And then use this factory class to stop or start all the animations at once. Or use one UIViewPropertyAnimator to perform all your animations and stop it.