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

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

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

7条回答
  •  没有蜡笔的小新
    2021-02-04 11:09

    As ’CGAffineTransformRotate’ uses radians as its unit of measure, and 180 degrees is the same as PI, instead of the math provided in other answers you can simply do:

    view.transform = CGAffineTransformRotate(view.transform, M_PI);
    

    Swift 3:

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

    If you plan on doing a lot of transforms, it's probably best to read up on radians, so you understand what is going on.

提交回复
热议问题