Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?
like image 906
Fattie Avatar asked Dec 15 '17 00:12

Fattie


People also ask

What is property animator in UIView?

A UIViewPropertyAnimator object lets you animate changes to views and dynamically modify your animations before they finish. With a property animator, you can run your animations from start to finish normally or you can turn them into interactive animations and control the timing yourself.

What is uiviewpropertyanimator in iOS?

UIViewPropertyAnimator was introduced in iOS 10. It allows you to create animations in object-oriented way. Let’s have at a sample animation created using UIViewPropertyAnimator.

How to delay animation in uiviewpropertyanimator?

Delaying the animation is quite easy too, just call the startAnimation function with the afterDelay param. UIViewPropertyAnimator adopts the UIViewImplicitlyAnimating protocol that provides the animator with some other interesting abilities.

What is uiviewanimationcurve?

As you have probably noticed with the previous example, together with the animation block we have defined two parameters: the duration of the animation and the animation curve, a UIViewAnimationCurve instance that can represents the most common curves (easeIn, easeOut, linear or easeInOut).


1 Answers

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.

like image 200
Arun Balakrishnan Avatar answered Oct 06 '22 23:10

Arun Balakrishnan