John John - 4 months ago 8
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))


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: