Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically rotate the view by 180 degrees on iOS?

How to programmatically rotate the view by 180 degrees in my iPhone App?

like image 339
meetpd Avatar asked Jul 25 '11 09:07

meetpd


1 Answers

Swift 4:

self.view.transform = CGAffineTransform(rotationAngle: .pi);

And a COMMENT (I evidently don't have enough points to enter my comment on his/her answer) for Benjamin Mayo or vtcajones answer of:

view.transform = view.transform.rotated(by: .pi)

This will work the first time, but the next time it is called it will rotate the view again, back to the original rotation, which is probably not what you want. It would be safer to set the transform value exactly each time.

like image 154
ByteSlinger Avatar answered Sep 28 '22 06:09

ByteSlinger