我正在使用UIViewPropertyAnimator
为淡入和淡出设置动画。传递重复选项不会重复播放动画,只能工作一秒钟。
我做错什么了吗?
有问题的代码:
private func faceFadeAnimator() {
faceAnimator = UIViewPropertyAnimator.runningPropertyAnimator(withDuration: 1, delay: 0, options: [.curveLinear, .repeat], animations: {
self.animatorImageView.alpha = self.animatorImageView.alpha == 1 ? 0 : 1
}, completion: { (position) in
})
}
解决方法:
private func faceFadeAnimator() {
faceAnimator = UIViewPropertyAnimator.runningPropertyAnimator(withDuration: 1, delay: 0, options: [.curveLinear], animations: {
UIView.setAnimationRepeatCount(1000)
self.animatorImageView.alpha = self.animatorImageView.alpha == 1 ? 0 : 1
}, completion: { (position) in
})
}