How to programmatically rotate the view by 180 deg

2019-03-13 02:56发布

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

7条回答
Rolldiameter
2楼-- · 2019-03-13 03:16

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.

查看更多
登录 后发表回答