我有一个自定义的视图,我想每3秒旋转90度,下面是我使用的代码
private func _rotateSelf(duration: Double = 1.0, delay: Double = 3.0) {
print("self._rotateSelf() called from UICustomView")
UIView.animate(withDuration: duration, delay: delay, options: [.curveEaseInOut], animations: {
// TODO: this only works on the first function call
self.transform = CGAffineTransform.identity.rotated(by: (.pi / 2))
}, completion: { finished in
if finished == true {
print("Animation finished")
self._rotateSelf()
}
})
}
问题是,动画仅在第一次调用该函数时才起作用.在那之后的每一次调用,都没有动画发生,函数只是被一次又一次地调用,最终冻结了应用程序.
我有什么不明白的吗?