How to get iPhones current orientation?

后端 未结 5 1501
忘掉有多难
忘掉有多难 2021-01-30 16:19

Is there a special method to get iPhones orientation? I don\'t need it in degrees or radians, I want it to return an UIInterfaceOrientation object. I just need it for an if-else

5条回答
  •  难免孤独
    2021-01-30 17:09

    As discussed in other answers, you need the interfaceOrientation, not the deviceOrientation.

    The easiest way to get to this, is to use the property interfaceOrientation on your UIViewController. (So most often, just: self.interfaceOrientation will do).

    Possible values are:

    UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,
    UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
    UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,
    UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft
    

    Remember: Left orientation is entered by turning your device to the right.

提交回复
热议问题