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?
A transformation matrix is not incredibly difficult. It's quite simple, if you use the supplied functions:
(.34906585 is 20 degrees in radians)
Swift 5:
Swift version:
Swift 4.0
As far as I know, using the matrix in
UIAffineTransform
is the only way to achieve a rotation without the help of a third-party framework.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.
Swift 4:
where 1.57 is the radian value for 90 degree