Repeat/Autoreverse animations in iOS 13.x

折月煮酒 提交于 2020-04-13 09:09:52

问题


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


回答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
})


来源:https://stackoverflow.com/questions/58549065/repeat-autoreverse-animations-in-ios-13-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!