Using UIViewPropertyAnimator with repeat and autoreverse options

314 views Asked by At

I went over every existing similar question here and couldn't find a solution.

I'm trying to do the following property animation that should autoreverse and repeat until an event happens, and then I'll stop it:

lookupButtonAnimator = 
UIViewPropertyAnimator.runningPropertyAnimator(withDuration: 0.6,
                                               delay: 0,
                                               options: [.curveEaseIn, .autoreverse, .repeat]) {
                self.lookupButton.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)   
            }

The compiler ignores the .autoreverse and .repeat options, and only performs the animation once.

What did work for me, though, is adding the following two lines inside the animation closure:

                UIView.setAnimationRepeatCount(Float.infinity)
                UIView.setAnimationRepeatAutoreverses(true)

However, Xcode does not like this, and presents two warnings:

'setAnimationRepeatCount' was deprecated in iOS 13.0: Use the block-based animation API instead 'setAnimationRepeatAutoreverses' was deprecated in iOS 13.0: Use the block-based animation API instead

Is there any possible way to autoreverse and repeat a property animation without having to use deprecated code?

Please do not suggest to use UIView.animate(..) instead of UIViewPropertyAnimator.

0

There are 0 answers