Reputation: 183
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
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