iphone - 游戏中心登录锁定横向仅在 iOS 6 中

标签 iphone game-center uiinterfaceorientation ios6

加载游戏中心时,其默认方向为纵向。 为了将其锁定在横向模式,添加了一个类别。

@implementation GKMatchmakerViewController (LandscapeOnly)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return ( interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL)shouldAutorotate {
    return NO;
}
@end

在 iOS 6 以下运行良好。但在 iOS6 中显示错误。

由于未捕获的异常“UIApplicationInvalidInterfaceOrientation”而终止应用程序,原因:“支持的方向与应用程序没有共同的方向,并且 shouldAutorotate 返回 YES”

请解释一下解决方案。

最佳答案

最后,我按照 Apple 的 iOS 6 release notes 中提到的解决方法避免了崩溃。 .

解决方法:

1.应用程序应提供委托(delegate)方法 application:supportedIntefaceOrientationsForWindow 并确保 Portrait 是返回的掩码值之一。

- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{

    return UIInterfaceOrientationMaskAllButUpsideDown;
}

<强>2。当涉及 UIBNavigationController(或 UIViewController)时,子类化 UINavigationController/UIViewController 并覆盖supportedInterfaceOrientations。

 - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskLandscape;
    }

还有

在构建摘要中支持的方向选择横向右侧和横向左侧。

现在游戏中心工作正常,没有崩溃。

关于iphone - 游戏中心登录锁定横向仅在 iOS 6 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12488838/

相关文章:

ios - 在 Swift 中,如何在启动后立即正确获取设备方向?

iphone - 如何在 iOS 中通过 wifi 传输大文件

ios - Objective-c:当所有线程完成时返回

ios - 使用时标签显示文本效果不佳[cell setNeedsDisplay]

android - 统一社交API

ios - 选择游戏中心部分目的地

ios - UICollectionView 布局更新 - 项目大小不变

iphone - 技巧 preferredInterfaceOrientationForPresentation 在 vi​​ewController 更改时触发

jquery - 如何在 iPad/iPhone 上提高网站性能?

ios - JSON 文本未以数组或对象开头,并且未设置允许片段的选项