带导航控制器定位的Tabbar控制器ios 6

我目前正在一个项目,我们有一个标签栏控制器4个选项卡,每个选项卡有一个导航控制器。 在每个导航控制器上都有多个视图控制器。

我在这里和其他地方读了很多post,目前我们做了以下工作:

子类UITabbarcontroller

- (BOOL)shouldAutorotate { return [[[self.viewControllers objectAtIndex:self.selectedIndex]topViewController] shouldAutorotate]; } - (NSUInteger) supportedInterfaceOrientations { return [[[self.viewControllers objectAtIndex:self.selectedIndex]topViewController]supportedInterfaceOrientations]; } - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ return [[[self.viewControllers objectAtIndex:self.selectedIndex]topViewController] shouldAutorotateToInterfaceOrientation:toInterfaceOrientation]; } 

这工作很好,如果我们在每个viewcontrollers中指定以下内容:

 - (NSUInteger) supportedInterfaceOrientations{ return UIInterfaceOrientationMaskPortrait; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ return YES; } 

如预期的那样,这会将其locking到肖像。

但现在真正的问题发生! 如果我们在我们的视图控制器中的其中一个选项卡指定它应该旋转到风景它工作正常,但是当我们然后改变选项卡它仍然在风景,这不是我们想要的!

所以总结一下,有没有人得到一个解决scheme,如何locking几乎所有的视图到一个给定的方向期待一个,并可以改变标签,他们在你指定的方向(这里的肖像)?

我也读了这个postiOS 6的UITabBarController支持与当前的UINavigation控制器的方向 ,但作为一个评论也提到“这几乎为我工作的问题是,如果我已经在横向,当我切换到一个肖像标签只有查看它仍然在旋转的肖像修复它,它不会旋转回风景,但我仍然需要它在肖像,当它第一次加载“这几乎是相同的在这里..

我自己有这个问题,我找出了一个解决scheme,它不漂亮,但它的工作原理。

在你的TabbarController子类中实现这个tabbarcontroller委托function(记得设置委托):

 -(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{ int selected = self.selectedIndex; UIViewController *con = [[UIViewController alloc] initWithNibName:@"XIBName" bundle:nil]; [[self.viewControllers objectAtIndex:selected] pushViewController:con animated:NO]; [[self.viewControllers objectAtIndex:selected]popViewControllerAnimated:NO]; [[self.viewControllers objectAtIndex:selected] setDelegate:nil]; } 

在tabs navigationcontroller中的uinavigationcontroller上的push和pop会让tabbarcontroller再次触发它的Orientations函数,如果你正确的实现了方向代码,它会改变到你想要的方向。

我希望这可以帮助,如果我需要解释任何细节,请免费发表评论。

最好的问候莫滕