如何在tabbar中允许vc的vc自动转换?

问题描述:

我有一个标签栏视图控制器,其中包含一些导航控制器,每个都有一个根视图控制器。所有东西都只能以肖像呈现。一切都很好。其中一个子视图控制器使用它的导航vc推动另一个视图控制器,并且我希望允许旋转到其上。如何在tabbar中允许vc的vc自动转换?

Tabbar vc 
    nav vc/vc1 
    nav vc/vc2 
    nav vc/vc3 
     pushes new vc4 <- ONLY this one should autorotate. Further more, if you're in landscape mode in this vc and hit 'back', it goes back in portrait. 

应用程序的'行'这样做 - 实际的'聊天'窗口可以自动旋转。

请给我代码! ;)我希望它不需要搞乱变换...

为了支持你的UITabBarController应用程序的自动旋转,你需要在你的tabBarController上继承视图控制器的旋转调用,并询问当前呈现的视图控制器是否他支持新的方向。在你的具体情况下,vc4会被问及他是否支持方向改变,所以标签栏可以在被询问时旋转。

采取在看这个问题:tabBarController and navigationControllers in landscape mode, episode II

+0

差不多!这确实允许vc4旋转到风景如我所愿。然而,当我弹出vc4,vc3仍然在风景 - 无论如何,我可以强制它的肖像? – Colin

+0

尝试调用[UIViewController attemptRotationToDeviceOrientation] – J2theC

+0

是的!!!哦,等待iOS5。当怪异的业务约束! – Colin

@Colin在乌尔的TabBar视图 - 控制,限制它potrait像

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

和UR新的视图 - 控制(VC4),其限制在风景。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight)); 
} 

希望它有帮助。

+0

不起作用。首先尝试。 – Colin

+0

只想问你如何在appdelegate中添加你的tabbarcontroller? bcoz它工作正常,如果你使用[self.window addSubview:tabbarcontroller.view]; – rehan