extensionでUIViewを拡張
extension UIView {
func rotate360Degrees(duration: CFTimeInterval = 1.0, completionDelegate: AnyObject? = nil) {
let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation")
rotateAnimation.fromValue = 0.0
rotateAnimation.toValue = CGFloat(M_PI)
rotateAnimation.duration = duration
if let delegate: CAAnimationDelegate = completionDelegate as! CAAnimationDelegate? {
rotateAnimation.delegate = delegate
}
self.layer.add(rotateAnimation, forKey: nil)
}
}
どこかで呼び出し
self.YOUR_SUBVIEW.rotate360Degrees()
参考
Rotate a view for 360 degrees indefinitely in Swift?