2012-09-19 4 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を追加する必要がありました。この答えで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/

関連する問題