Rotate UIButton 360 degrees

后端 未结 8 877
青春惊慌失措
青春惊慌失措 2021-02-07 01:52

I\'ve been trying to run an animation that rotates my UIButton 360 degrees using this code:

UIView.animateWithDuration(3.0, animations: {
  self.vin         


        
8条回答
  •  独厮守ぢ
    2021-02-07 02:09

    As discussed here, you can also use a CAAnimation. This code applies one full 360 rotation:

    Swift 3

    let fullRotation = CABasicAnimation(keyPath: "transform.rotation")
    fullRotation.delegate = self
    fullRotation.fromValue = NSNumber(floatLiteral: 0)
    fullRotation.toValue = NSNumber(floatLiteral: Double(CGFloat.pi * 2))
    fullRotation.duration = 0.5
    fullRotation.repeatCount = 1
    button.layer.add(fullRotation, forKey: "360")
    

    You will need to import QuartzCore:

    import QuartzCore
    

    And your ViewController needs to conform to CAAnimationDelegate:

    class ViewController: UIViewController, CAAnimationDelegate {
    
    }
    

提交回复
热议问题