在iOS 7中强制横向和自动旋转

问题描述:

我的应用程序应该只是风景,我在构建 iOS 6 及更早版本时没有遇到任何问题。现在使用 iOS 7,它根本不会轮换。

My app is supposed to be landscape only, and I had no problem with this when building for iOS 6 and earlier. Now with iOS 7, It won't rotate at all.

在我的应用设置中,我将其设置为仅左/右横向。在我的视图控制器中,我使用以下内容:

In my app settings, I have it set to landscape left/right only. In my view controller, i'm using the following:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
}

我也习惯使用它,现已弃用:

I also used to use this, which is now deprecated:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
    return UIInterfaceOrientationIsLandscape(orientation);
}

新的似乎是shouldAutorotate,但使用此崩溃我的应用程序。任何想法都将受到赞赏,因为我的应用程序*在我的iPad和模拟器中画像。谢谢!

The new one appears to be shouldAutorotate, but using this crashes my app. Any ideas on this would be appreciated, since my app is forced to portrait on my iPad and in the simulator. Thank you!

这解决了我的问题。我不确定为什么我之前遇到过问题,但我一定错过了尝试这个确切的组合(另外,info.plist应该设置支持的方向)。

This solves my problem. I'm not sure why I had issues before, but I must have missed trying this exact combination (also, info.plist should have the supported orientations set).

(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

(BOOL)shouldAutorotate {
    return YES;
}

编辑:我可能遇到模拟器问题,并且正在执行重置/重启和清理可能有助于修复。

edit: I may have having issues with the simulator, and doing a reset/restart and clean might have contributed to the fix.