Cesare Cesare - 11 months ago 48
Swift Question

How do I rotate an object for 360 degrees infinitely in Swift?

I want to rotate a

for 360 degrees, but I don't know how to do that. Here's my code:

UIView.animateWithDuration(1.2, delay: 0.0, options: UIViewAnimationOptions.Repeat, animations: {
// Rotate the image here
self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, 6.28318530717959)

// As the options are set to .Repeat, there is no completion
}, completion: nil)}

How do I rotate an object for 360 degrees infinitely?


I would stick it in a function like rotateImage() and in the completion code just call rotateImage() again. I think you should use M_PI (or the swift equivalent) for the rotation amount, though.