Rotate UIButton 360 degrees

后端 未结 8 876
青春惊慌失措
青春惊慌失措 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:28

    Swift 5. Try this, it worked for me

    UIView.animate(withDuration: 3) {
      self.yourButton.transform = CGAffineTransform(rotationAngle: .pi)
      self.yourButton.transform = CGAffineTransform(rotationAngle: .pi * 2)
     }
    
    0 讨论(0)
  • 2021-02-07 02:29

    You can use a trick: start rotating with 180 degrees first and then rotate with 360 degrees. Use 2 animations with delay. Try this.

    Swift 2

    UIView.animateWithDuration(0.5) { () -> Void in
      button.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
    }
    
    UIView.animateWithDuration(0.5, delay: 0.45, options: UIViewAnimationOptions.CurveEaseIn, animations: { () -> Void in      
      button.transform = CGAffineTransformMakeRotation(CGFloat(M_PI * 2))
    }, completion: nil)
    

    Swift 3, 4, 5

    UIView.animate(withDuration: 0.5) { () -> Void in
      self.settingsButton.transform = CGAffineTransform(rotationAngle: CGFloat.pi)
    }
    
    UIView.animate(withDuration: 0.5, delay: 0.45, options: UIViewAnimationOptions.curveEaseIn, animations: { () -> Void in
      self.settingsButton.transform = CGAffineTransform(rotationAngle: CGFloat.pi * 2.0)
    }, completion: nil)
    

    Hope this helps

    0 讨论(0)
提交回复
热议问题