IOS6轮换问题

我知道你必须使用IOS6的新的旋转方法,但似乎我写的方法不起作用。

我设置了我的plist文件来允许所有的旋转,但不是portraitUpsideDown

然后我在我的appDelegate中有以下内容:

self.navController = [[UINavigationController alloc] initWithRootViewController:self.viewController]; [self.window setRootViewController:navController]; //add nav controller to be the root view 

然后在我的rootView,推到另一个控制器,我有:

 WebViewViewController *webController = [[JBWebViewViewController alloc] init]; webController.urlString = urlName; [self.navigationController pushViewController:webController animated:YES]; 

在Web控制器中我有:

 #pragma mark - System Rotation Methods //for any version before 6.0 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { //only allow landscape return (interfaceOrientation == UIInterfaceOrientationPortrait); } /for 6.0+ - (BOOL)shouldAutorotate{ return NO; } - (NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskPortrait; } 

我想要做什么,是允许在根视图3旋转,但切换到Web视图(注意我做推导航,不添加子视图),我只想让肖像视图。

有人帮助我

——-更新———-

我已经创build了我自己的UINavigationController的navController子类,我有一个布尔landscapeModeOn,我可以设置告诉自动旋转规格

 #pragma mark - System Rotation Methods //for any version before 6.0 - (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)interfaceOrientation { if (landscapeModeOn) { return interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown; } else { return interfaceOrientation == UIInterfaceOrientationPortrait; } } //for 6.0+ - (NSUInteger)supportedInterfaceOrientations{ if (landscapeModeOn) { return UIInterfaceOrientationMaskAllButUpsideDown; } else { return UIInterfaceOrientationMaskPortrait; } } - (BOOL)shouldAutorotate{ UIInterfaceOrientation ori = [UIDevice currentDevice].orientation; if (landscapeModeOn) { return ori != UIInterfaceOrientationPortraitUpsideDown; } else { return ori == UIInterfaceOrientationPortrait; } } 

在子视图加载中,我这样做:

 - (void)viewWillAppear:(BOOL)animated{ //get nav controller and turn off landscape mode JBNavController *navController = (JBNavController*)self.navigationController; [navController setLandscapeModeOn:NO]; [navController shouldAutorotate]; } 

——————–请参阅最佳答案的引用对于IOS6,苹果现在专注于将Storyboard的AutoLayout与新的旋转定义一起使用,难以修复基于ios 4.3和ios 5编码结构的IOS6的小错误

从applefreak,他的build议暗示:

你的情况主要挑战是不处理方向。 其实它是locking不同的视图控制器到特定的方向

虽然手动旋转视图似乎真的很难做到没有任何错误,但它似乎是我现在正在尝试的唯一的解决scheme,将解决一旦解决

以下代码是错误的!

 - (BOOL)shouldAutorotate{ return NO; } - (NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskPortrait; } 

请记住,仅当shouldAutoRotate返回YES时,才会调用supportedInterfaceOrientations。 现在,根视图控制器决定它是否是儿童旋转。

在你的情况下,我会build议有一个基类控制器到你的self.viewController和设置self.viewController根视图控制器不navigationController否则旋转方法将不会被调用! 我遇到了同样的问题。 您应该与基本视图控制器有一个HAS-A关系,它是子级。 从ShouldAutoRotate返回是/否根据活动的孩子和相同的支持的方向。 如果你遵循这个架构,那么复杂的应用程序将是一致的。

例如在你的情况下,BaseviewController应该从shouldAutoRotate返回YES,并在webviewController处于活动状态时从支持的方向委托中返回UIInterfaceOrientationPortrait。 我希望这是有道理的。

对于你的情况,你将不得不inheritance你的NavigationController,并添加shouldAutorotate和supportedInterfaceOrientations方法。 iOS6现在向iOS5询问您的导航堆栈,所以它会首先询问您的NavigationController,如果返回YES,它甚至不会咨询它的子视图控制器。 要解决这个问题,你必须自己添加逻辑

所以在你的subclassed导航控制器中,你手动询问你当前的viewcontroller是自动旋转的能力:

 - (BOOL)shouldAutorotate { return self.topViewController.shouldAutorotate; } - (NSUInteger)supportedInterfaceOrientations { return self.topViewController.supportedInterfaceOrientations; } 

在你的个人viewcontrollers你现在可以实现这些function,并让他们返回你想问题中定义的值。

我希望这是有道理的。

它是iOS5和iOS6的通用代码

 - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration { if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) { // here to implement landscope code } else { // here to implement setframePortrait } }