1

赤い背景とボタンが付いた単純なアプリケーションを作成しました (この問題を理解するため)。アプリはランドスケープ モードであり、iOS6 フレームワークで構築されています。

サポートされているインターフェイスの向きの pList プロパティを次のように設定しました: 横向き (右のホーム ボタン)

メソッド -(BOOL)shouldAutorotate および -(NSUInteger)supportedInterfaceOrientations をビュー コントローラーに配置し、UINavigationController を使用せずに Windows rootViewController として開始すると、横向きになります。

ただし、以下の例のようにサブクラス化された UINavigationController を使用し、 -(BOOL)shouldAutorotate および -(NSUInteger)supportedInterfaceOrientations を実装すると、横向きは達成されず、 -(BOOL)shouldAutorotate は呼び出されません。

サブクラス化された UINavigationController に次のコードがあります。

 //For iOS 5.x and below
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
 {
  return (interfaceOrientation != UIInterfaceOrientationLandscapeRight);
 }

//For iOS 6.0
-(NSUInteger)supportedInterfaceOrientations
{
 return UIInterfaceOrientationMaskLandscapeRight;
}

-(BOOL)shouldAutorotate
{
return YES;
}

私の appDelegate には、次のメソッドがあります。

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{



self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];

viewController = [[MDViewController alloc] init]; //a very simple viewcontroller containing button on red background which should be in landscape mode
navigationController = [[MDNavigationController alloc] initWithRootViewController:viewController];
[self.window setRootViewController:navigationController.topViewController];

[self.window makeKeyAndVisible];
return YES;
}

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:  (UIWindow *)window {
   return UIInterfaceOrientationMaskLandscapeRight;
 }

私が実装した同様の質問に対する無数の回答を見てきましたが、それらが機能しないことがわかりました。ありがとう。

4

1 に答える 1

2

これを行うべきではありません:

[self.window setRootViewController:navigationController];

それ以外の:

[self.window setRootViewController:navigationController.topViewController];

于 2012-10-25T23:49:49.530 に答える