Swift-类似风车旋转动画的实现

代码实现如下:
/// 风车视图的旋转
    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
        // 解决动画结束后回到原始状态的问题
        animation.isRemovedOnCompletion = false
        animation.fillMode = kCAFillModeForwards
        animation.repeatCount = MAXFLOAT // 一直旋转的话,就设置为MAXFLOAT
        // 定义动画的节奏
//        animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)
        view.layer.add(animation, forKey: nil)
    }

你可能感兴趣的:(Swift-类似风车旋转动画的实现)