Repeat/Autoreverse 个动画 iOS 13.x
Repeat/Autoreverse animations in iOS 13.x
以前在 swift 中你可以这样做:
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.setAnimationRepeatCount
和 UIView.setAnimationRepeatAutoreverses
上有一条弃用消息。有谁知道他们被什么取代了?我仍然可以使用 UIViewPropertyAnimator
,还是必须使用 CABasicAnimation
之类的东西?
消息是:
'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
你可以这样做:
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)
对于所有可能的调用,您可以查看this link
此外,如果你真的需要UIViewPropertyAnimator
,它有一个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
})
以前在 swift 中你可以这样做:
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.setAnimationRepeatCount
和 UIView.setAnimationRepeatAutoreverses
上有一条弃用消息。有谁知道他们被什么取代了?我仍然可以使用 UIViewPropertyAnimator
,还是必须使用 CABasicAnimation
之类的东西?
消息是:
'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
你可以这样做:
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)
对于所有可能的调用,您可以查看this link
此外,如果你真的需要UIViewPropertyAnimator
,它有一个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
})