How to get iPhones current orientation?

后端 未结 5 1539
忘掉有多难
忘掉有多难 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-30 17:20

    UIInterfaceOrientation is now deprecated, and UIDeviceOrientation includes UIDeviceOrientationFaceUp and UIDeviceOrientationFaceDown so can't be relied on to give you the interface orientation.

    The solution is pretty simple though

    if (CGRectGetWidth(self.view.bounds) > CGRectGetHeight(self.view.bounds)) {
        // Landscape
    } else {
        // Portrait
    }
    

提交回复
热议问题