我想将影像检视无限期旋转360度。
UIView.animate(withDuration: 2, delay: 0, options: [.repeat], animations: { self.view.transform = CGAffineTransform(rotationAngle: 6.28318530717959) }, completion: nil)
我该怎么做?
从早期答案编译而来的Swift 2.x无限期旋转UIView的方法:
// Rotate <targetView> indefinitely private func rotateView(targetView: UIView, duration: Double = 1.0) { UIView.animateWithDuration(duration, delay: 0.0, options: .CurveLinear, animations: { targetView.transform = CGAffineTransformRotate(targetView.transform, CGFloat(M_PI)) }) { finished in self.rotateView(targetView, duration: duration) } }
更新Swift 3.x
// Rotate <targetView> indefinitely private func rotateView(targetView: UIView, duration: Double = 1.0) { UIView.animate(withDuration: duration, delay: 0.0, options: .curveLinear, animations: { targetView.transform = targetView.transform.rotated(by: CGFloat(M_PI)) }) { finished in self.rotateView(targetView: targetView, duration: duration) } }