如何在iOS 6中以编程方式获取设备的当前方向?

问题描述:

我开发了iOS应用程序并在iOS6设备上进行了测试。在测试时,我意识到我的应用程序没有按预期响应方向更改。

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.

这是我的代码:

// Autorotation (iOS >= 6.0)
- (BOOL) shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationMaskPortrait;
}

准确地说,我想知道在iOS中的方向更改中调用哪些方法。

Precisely, I want to know that what Methods are called on Orientation Changes in iOS.

你可以尝试这个,可以帮助你:

You can try this, may help you out:

如何在iOS 6中以编程方式更改设备方向


OR

OR

Objective-c:

UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]

Swift:

if UIDevice.current.orientation.isLandscape {
    // Landscape mode
} else {
    // Portrait mode
}