How can I rotate an UIImageView by 20 degrees?

Thanks picture Thanks · May 12, 2009 · Viewed 43.5k times · Source

What do I have to do, if I need to rotate a UIImageView? I have a UIImage which I want to rotate by 20 degrees.

The Apple docs talk about a transformation matrix, but that sounds difficult. Are there any helpful methods or functions to achieve that?

Answer

alexmorhun picture alexmorhun · Mar 15, 2012

If you want to turn right, the value must be greater than 0 if you want to rotate to the left indicates the value with the sign "-". For example -20.

CGFloat degrees = 20.0f; //the value in degrees
CGFloat radians = degrees * M_PI/180;
imageView.transform = CGAffineTransformMakeRotation(radians);

Swift 4:

let degrees: CGFloat = 20.0 //the value in degrees
let radians: CGFloat = degrees * (.pi / 180)
imageView.transform = CGAffineTransform(rotationAngle: radians)