Swift Continuous Rotation Animation not so continuous

前端 未结 3 1893
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-04 18:59

Here is my code. Intent is to continuously rotate the UIImageView named swirls[l]. However, there is a small pause between every rotation start/end. I have gone through every si

3条回答
  •  别跟我提以往
    2021-02-04 19:27

    If you want to continuous rotate Button or View and stop that rotation whenever you want then you can try this: For start rotation:

    @IBOutlet weak var RotateBtn: UIButton!
    var timeTimer: Timer?
    
    viewDidLoad()
    {
      self.rotateView()
      timeTimer = Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(self.rotateView), userInfo: nil, repeats: true)
    }
    
    func rotateView()
    {
        UIView.animate(withDuration: 0.5, delay: 0, options: .curveLinear, animations: { () -> Void in
            self.RotateBtn.transform = self.RotateBtn.transform.rotated(by: CGFloat(M_PI_4))
        })
    }
    

    If you want to stop rotation then use:

    @IBAction func StopBtn_Pressed(_ sender: AnyObject)
    {
       timeTimer?.invalidate()
       self.RecordBtn.layer.removeAllAnimations()
    } 
    

提交回复
热议问题