-1

I am trying to make this UIView rotate forever:

let options = UIViewAnimationOptions.autoreverse.union(UIViewAnimationOptions.repeat)

UIView.animate(withDuration: 5, delay: 0, options: options, animations: {            
    self.transform = CGAffineTransform(rotationAngle: CGFloat(2 * M_PI))
}, completion: { _ in })

Currently it does nothing because the rotation angle is the same position is it on right now. When I try something like M_PI it works and goes back and forth like it should, however it only does it halfway.

I am wondering how I can continue this rotation forever in a full 360 degree motion.

I tried this: UIView Infinite 360 degree rotation animation? which has the same issue I do, but I cannot figure out how to get it to work since Obj-C -> Swift has many changes. Would rather use UIView.animate other than CAAnimation, but not sure if that is the only other way.

Community
  • 1
  • 1
ngngngn
  • 579
  • 4
  • 18
  • "Would rather use UIView.animate other than CAAnimation" Then you have not understood the linked answers, which show clearly why that's impossible. You _must_ use CABasicAnimation to do this reliably. – matt Oct 04 '16 at 22:24
  • I did not know that. Thank you, I will check it out – ngngngn Oct 04 '16 at 22:35

1 Answers1

1

Use CABasicAnimation, not view animation, and rotate additively, not to an absolute value. It will also help if you rotate 180 degrees additively forever as this is easier to express.

matt
  • 515,959
  • 87
  • 875
  • 1,141