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

1

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?
Revet answered 15/12, 2017 at 0:21 Comment(4)
Any update on this by any chance?Cumine
a good question @SwiftRabbit, and no nothing more ! :ORevet
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?Whiteside
"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?Revet
I
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.

Interesting answered 12/2, 2018 at 15:23 Comment(2)
As it says "Or do you really have to keep a reference to every single animation?"Revet
either use one animator instance or track all the animator instancesInteresting

© 2022 - 2024 — McMap. All rights reserved.