ios 6.0 - 横向不工作 - 子类UINavigationController从不调用shouldAutorotate方法

时间:2012-10-25 17:02:17

标签: uinavigationcontroller ios6 landscape uiinterfaceorientation autorotate

我创建了一个简单的应用程序,它有一个红色背景和一个按钮(为了解这个问题)。该应用程序处于横向模式,并使用iOS6框架构建。

我已将支持的界面方向pList属性设置为仅具有:Landscape(右主页按钮)

如果我在视图控制器中放置方法 - (BOOL)shouldAutorotate和 - (NSUInteger)supportedInterfaceOrientations并将其作为windows rootViewController启动而不使用UINavigationController,则可以实现横向定位。

但是,如果我使用类似下面示例中的子类UINavigationController并实现 - (BOOL)shouldAutorotate和 - (NSUInteger)supportedInterfaceOrientations,则不会实现横向和 - (BOOL)永远不会调用.Autorotate。

我的Subclassed 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;
 }

我已经看到了我实施的类似问题的无数答案,但发现它们无法正常工作。 感谢。

1 个答案:

答案 0 :(得分:2)

你不应该这样做:

  

[self.window setRootViewController:navigationController];

而不是:

  

[self.window setRootViewController:navigationController.topViewController];