Cesare Cesare - 7 months ago 19
Swift Question

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

I want to rotate a

UIImageView
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?

Answer

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.

Comments