美文网首页
swift 一个方法调用实现imageView旋转

swift 一个方法调用实现imageView旋转

作者: 9e5f2143c765 | 来源:发表于2017-05-10 16:32 被阅读939次

给imageView 添加分类,然后直接调用
//开始旋转
imageView. rotate360DegreeWithImageView()
//停止旋转
imageView.stopRotate()

/// imageView 旋转
    ///
    /// - Parameters:
    ///   - duration: 周期 (控制速度:2--10)
    ///   - repeatCount: 次数
    func rotate360DegreeWithImageView(duration:CFTimeInterval , repeatCount :Float ) {
        
        //让其在z轴旋转
        let rotationAnimation  = CABasicAnimation(keyPath: "transform.rotation.z")
        
        //旋转角度
        rotationAnimation.toValue = NSNumber(value:  Double.pi * 2.0 )
        
         //旋转周期
        rotationAnimation.duration = duration;
        
        //旋转累加角度
        rotationAnimation.isCumulative = true;
        
        //旋转次数
        rotationAnimation.repeatCount = repeatCount;
        
        self.layer .add(rotationAnimation, forKey: "rotationAnimation")
        
    }
    //停止旋转
    func stopRotate() {
        
        self.layer.removeAllAnimations()
    }

相关文章

网友评论

      本文标题:swift 一个方法调用实现imageView旋转

      本文链接:https://www.haomeiwen.com/subject/risgtxtx.html