Cesare Cesare - 2 years ago 130
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download