13

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?
Fattie
  • 30,632
  • 54
  • 336
  • 607
  • Any update on this by any chance? – Swift Rabbit Feb 07 '18 at 17:08
  • a good question @SwiftRabbit, and no nothing more ! :O – Fattie Feb 07 '18 at 18:49
  • 1
    You ask “Or do you really have to keep a reference to every single animation?” How would you even get a reference to an animation, since `UIViewPropertyAnimator` doesn't return references to the animations it creates? Did you mean “keep a reference to every single **animator**?” Are you using many animators or a single animator? – rob mayoff Feb 12 '18 at 15:43
  • "How would you even get a reference to an animation" well that's what I'm wondering - is there a way to have it spit them all out? – Fattie Feb 13 '18 at 15:35

1 Answers1

6

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.

Arun Balakrishnan
  • 1,362
  • 10
  • 22