In Swift, how to get the device orientation correctly right after it's launched?

后端 未结 5 1830
孤独总比滥情好
孤独总比滥情好 2021-01-12 22:45

I use following code to see if the device is in landscape mode or not:

UIDevice.currentDevice().orientation.isLandscape.boolValue

It works

5条回答
  •  逝去的感伤
    2021-01-12 23:17

    This worked for me:

    if UIScreen.main.bounds.width > UIScreen.main.bounds.height{
        print("Portraitmode!")
    }
    

    It works on all devices based on the display dimensions: https://developer.apple.com/library/archive/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/Displays/Displays.html

提交回复
热议问题