John
John

Reputation: 183

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))

Upvotes: 1

Views: 58

Answers (1)

Alessandro Ornano
Alessandro Ornano

Reputation: 35382

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 {
                        self.rotateImageView()
                    }
        }
}

If you want to stop it you can call:

self.imageView.layer.removeAllAnimations()

Upvotes: 3

Related Questions