首页 文章

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

提问于
浏览
1

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

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

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

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

我的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 回答

  • 2

    你不应该这样做:

    [self.window setRootViewController:navigationController];

    代替:

    [self.window setRootViewController:navigationController.topViewController];

相关问题