在iOS 13.x中重复/自动反转动画 [英] Repeat/Autoreverse animations in iOS 13.x

查看:170
本文介绍了在iOS 13.x中重复/自动反转动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前,您可以快速执行以下操作:

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
}

但是,现在在UIView.setAnimationRepeatCountUIView.setAnimationRepeatAutoreverses上有一个弃用消息.有人知道他们被替换了吗?我仍然可以使用UIViewPropertyAnimator,还是必须去CABasicAnimation之类的东西?

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?

消息为:

'setAnimationRepeatCount'在iOS 13.0中已被弃用:改为使用基于块的动画API

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

'setAnimationRepeatAutoreverses'已在iOS 13.0中弃用:改为使用基于块的动画API

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

推荐答案

您可以执行以下操作:

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

此外,如果您确实需要UIViewPropertyAnimator,则它具有相似的init :

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

这篇关于在iOS 13.x中重复/自动反转动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆