I was messing with the documentation of UIViewPropertyAnimator and I was hoping to find a way to combine two UIViewPropertyAnimator.
Something like this:
let firstAnimator = UIViewPropertyAnimator(
duration: 2,
dampingRatio: 0.4,
animations: animation1
)
let secondAnimator = UIViewPropertyAnimator(
duration: 2,
dampingRatio: 0.4,
animations: animation2
)
firstAnimator.addAnimator(secondAnimator, withDelay: 1)
firstAnimator.startAnimation()
I am missing a UIViewPropertyAnimatorGroup or something like this does this even exist?
The current recommended method is to use an array of UIViewPropertyAnimator
's.
This approach is outlined in detail in a WWDC 2017 presentation titled "Advanced Animations with UIKit". https://developer.apple.com/videos/play/wwdc2017/230/
The essential bit is to keep all your animators together, and whenever a gesture-based event occurs you can apply an update to all animators at once.
var runningAnimators = [UIViewPropertyAnimator]()
// later in the code...
runningAnimators.forEach { $0.pauseAnimation() } // pause all animations
I have an open-source repo on GitHub that gives an example of using multiple property animators in this way: https://github.com/nathangitter/interactive-animations
For your specific question, why do you need multiple property animators? Generally you only need multiple animators when you want a single animation with multiple timing curves, but it looks like your timing parameters are identical.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With