Repeating UIView animation a fixed number of times

I have a UIView animation that I want to reverse and repeat 5 times. Prior to iOS 13, I used the following code -

UIView.animate(

withDuration: 0.5,

delay: 0.0,

options: [.repeat, .autoreverse],

animations: {

UIView.setAnimationRepeatCount(5.0)


//stuff to be animated

},

completion: {(hasFinished:Bool) in

}

)

Now it seems that from iOS 13 onwards, UIView.setAnimationRepeatCount is deprecated. Xcode gives a deprecation warning with the message "use the block based animation API instead". I've searched the docs and cant seem to find a substitute.
What is the alternative process to repeat and reverse an animation a fixed number of times?

Post not yet marked as solved Up vote post of ayushv2005 Down vote post of ayushv2005
2.1k views

Replies

Dear UIKit team,
Throw us a bone here:
setAnimationRepeatCount - Deprecated iOS13 - No advice on replacement
setAnimationRepeatAutoReverses - Deprecated iOS13

However:
UIView block based animation - NOT Deprecated
UIViewAnimationOptionRepeat - NOT Deprecated
UIViewAnimationOptionAutoreverse - NOT Deprecated
UIViewPropertyAnimator - No Repeat Count Option

Not ALL repeating animations are appropriate as springs!