UIViewPropertyAnimator重复不起作用

时间:2018-07-23 08:47:55

标签: ios swift animation uiview uiviewanimation

我正在使用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
        })
    }

0 个答案:

没有答案