John John - 2 years ago 85
iOS Question

Why UIImageView rotates only once?

On button click I'm using this code line to rotate my UIImageView. But it works only once. How can I make it infinity times in every button click?

self.imageView.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))

Answer Source

You must use CGAffineTransformRotate instead of CGAffineTransformMakeRotation:

func rotateImageView() {   
     UIView.animateWithDuration(1, delay: 0, options: UIViewAnimationOptions.CurveLinear, animations: { () -> Void in
                self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, CGFloat(M_PI_2))
                }) { (finished) -> Void in
                    if finished {

If you want to stop it you can call:

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