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

后端 未结 7 1177
面向向阳花
面向向阳花 2021-02-04 10:15

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

7条回答
  •  你的背包
    2021-02-04 11:07

    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.

提交回复
热议问题