加载游戏中心时,其默认方向为纵向。 为了将其锁定在横向模式,添加了一个类别。
@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/