5

Previously in swift you could do this:

let animator = UIViewPropertyAnimator(duration: 0.25, curve: .easeIn) {
  UIView.setAnimationRepeatCount(Float.infinity)
  UIView.setAnimationRepeatAutoreverses(true)
  let transform = CATransform3DIdentity
  let rotate = CATransform3DRotate(transform, 45, 1, 1, 0)
  self.ex.layer.transform = rotate
}

However, now there is a deprecation message on UIView.setAnimationRepeatCount and UIView.setAnimationRepeatAutoreverses. Does anybody know what they was replaced with? Am I still able to use UIViewPropertyAnimator, or do I have to go to something like CABasicAnimation?

Messages are:

'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

Community
  • 1
  • 1
rgahan
  • 667
  • 8
  • 17

1 Answers1

1

You can do something like this:

UIView.animate(withDuration: 0.25, delay: 0, options: [.autoreverse, .curveEaseIn, .repeat], animations: {
    let transform = CATransform3DIdentity
    let rotate = CATransform3DRotate(transform, 45, 1, 1, 0)
    self.ex.layer.transform = rotate
}, completion: nil)

For all the possible calls, you can check this link

In addition, if you really needs the UIViewPropertyAnimator, it has a similar init:

 UIViewPropertyAnimator.runningPropertyAnimator(withDuration: 0.25, delay: 0, options: [.autoreverse, .curveEaseIn, .repeat], animations: {
    let transform = CATransform3DIdentity
    let rotate = CATransform3DRotate(transform, 45, 1, 1, 0)
    self.ex.layer.transform = rotate
})
alxlives
  • 5,084
  • 4
  • 28
  • 50
  • 1
    Is it possible to use the `UIViewPropertyAnimator` method and have that same functionality, or is Apple changing it so that method can only be used for non-repeating animations? – rgahan Oct 24 '19 at 21:19
  • 1
    Yes, the problem is the deprecated `setAnimationRepeatCount` and `setAnimationRepeatAutoreverses` functions from the `UIView`, Apple started putting those options in code blocks. Just edited the answer. – alxlives Oct 24 '19 at 21:33
  • 8
    Just for anyone else, the UIViewPropertyAnimator API ignores the .autoreverse and .repeat options – Andrew Dec 11 '19 at 16:06
  • 1
    Yeah, this didn't work for me.. Using .repeat for the UIViewPropertyAnimator doesn't work. – Sti Dec 16 '19 at 13:57