How to get current orientation of device programmatically in iOS 6?

前端 未结 8 812
庸人自扰
庸人自扰 2020-12-30 23:50

I have developed an iOS App and tested it on iOS6 device. While testing, I realized that my App is not responding to Orientation changes as expected.

Here is my Code

8条回答
  •  抹茶落季
    2020-12-31 00:31

    UIDevice.current.orientation.isLandscape
    

    The accepted answer reads the orientation of the device as above, which can be reported differently than the orientation of your view controller(s), particularly if your device is held in an almost horizontal position.

    To get the orientation of your view controller specifically, you can use its interfaceOrientation property, which is deprecated since iOS 8.0 but still reports correctly.

提交回复
热议问题