2012-09-19 38 views
20

装入游戏中心时,其默认方向为纵向。 为了锁定横向模式,添加了一个类别。游戏中心登录锁定只在i OS 6

@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”

请解释的解决方案。

回答

39

最后,我通过遵循Apple iOS 6 release notes中提到的解决方法避免了崩溃。

解决方法:

1.Apps should provide the delegate methodapplication:supportedIntefaceOrientationsForWindow and ensure that portrait is one of the returned mask values.

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

    return UIInterfaceOrientationMaskAllButUpsideDown; 
} 

2.当UIBNavigationController(或一个UIViewController)参与,子类的UINavigationController/UIViewController中和压倒一切supportedInterfaceOrientations。

- (NSUInteger)supportedInterfaceOrientations 
    { 
     return UIInterfaceOrientationMaskLandscape; 
    } 

而且

In buid summary supported orientations selected landscape right and landscape left.

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

+0

真棒!你救了我的屁股:) – yonix

+0

谢谢!我的屁股被保存了:) –

+1

也为我工作,但在我的情况下,我没有使用UIBNavigationController而是UIViewController(它的子类),但我仍然必须将方法2添加到它。你可能想在这个答案中用UIViewController替换UIBNavigationController。 –

0

必须添加1个小东西。在这个愚蠢的问题上挣扎2天左右。如果上述方法不帮助你,你有UINavigationController的invovled(你已经没有继承它),你需要以下内容(的appDelegate):

[window setRootViewController:navigationController]; // use this 
// instead of [self.window addSubview:navigationController.view]; 

感谢名单2 http://grembe.wordpress.com/2012/09/19/here-is-what-i/