2012-09-19 1 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.

UIBNavigationController (또는 UIViewController에)가 관여
- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window 
{ 

    return UIInterfaceOrientationMaskAllButUpsideDown; 
} 

2.은 UINavigationController /의 UIViewController과 겹쳐 supportedInterfaceOrientations 하위 클래스.

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

- (NSUInteger)supportedInterfaceOrientations 
    { 
     return UIInterfaceOrientationMaskLandscape; 
    } 

그리고

지금 게임 센터는 충돌없이 제대로 작동합니다.

+0

신난다! 당신은 내 엉덩이를 구해 줬어. – yonix

+0

고마워! 내 엉덩이도 저장되었습니다 :) –

+1

나를 위해 일한,하지만 내 경우에는 UIBNavigationController하지만 UIViewController (하위 클래스), 아직 나는 그것에 메서드 번호 2를 추가했다. 이 대답에서 UIBNavigationController를 UIViewController로 바꿀 수 있습니다. –

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/