代碼實現(xiàn)如下:
/// 風車視圖的旋轉(zhuǎn)
fileprivate func transformAnimation(view:UIView) {
let animation = CABasicAnimation(keyPath: "transform.rotation.z")
// 默認是順時針效果,若將formValue和toValue的值互換,則為逆時針效果
animation.fromValue = 0
animation.toValue = Double.pi*2
animation.duration = 2
animation.autoreverses = false
// 解決動畫結(jié)束后回到原始狀態(tài)的問題
animation.isRemovedOnCompletion = false
animation.fillMode = kCAFillModeForwards
animation.repeatCount = MAXFLOAT // 一直旋轉(zhuǎn)的話探熔,就設(shè)置為MAXFLOAT
// 定義動畫的節(jié)奏
// animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)
view.layer.add(animation, forKey: nil)
}