我有一个启动/停止按钮和一个图像视图,我想要旋转这个图像视图。当我按下按钮时,我希望开始旋转图像视图,并在再次按下按钮时停止旋转。目前我正在使用
UIView
动画,但我还没有找到一种停止视图动画的方法。我希望图像能够旋转,但当动画停止时,图像不应返回到起始位置,而是继续动画。var isTapped = true
@IBAction func startStopButtonTapped(_ sender: Any) {
ruotate()
isTapped = !isTapped
}
func ruotate() {
if isTapped {
UIView.animate(withDuration: 5, delay: 0, options: .repeat, animations: { () -> Void in
self.imageWood.transform = self.imageWood.transform.rotated(by: CGFloat(M_PI_2))
}, completion: { finished in
ruotate()
})
} }
这是我的代码,但它的表现不像我期望的那样。
CABasicAnimation
来实现启动/停止动画。 - Ahmad F