UINavigationController中的viewControllers有可能有不同的方向吗?

我希望所有的视图控制器只支持肖像模式,除了一个视图控制器让我们称之为“LandscapeSupportViewController”应该也支持横向模式。

问题是当我在LandscapeSupportViewController横向模式,然后推一个新的视图控制器,只支持肖像模式,推视图控制器也将在横向模式! 我怎么能强迫它成为肖像?

我看到几个应用程序,例如Skype iPhone应用程序,消息选项卡只是肖像 – >然后,如果你按下input消息本身,你会得到一个支持风景的视图控制器, 因为它是有意义的启用风景模式时用户正在聊天 – >然后如果你按下查看个人资料,一个新的视图控制器将被推动,但肖像! 如果你回去也会发生同样的情况,即使你从风景中走过来,你也不得不回到人像。

谢谢

我曾经让学生尝试完成你正在努力完成的任务,经过大量的研究之后,普遍的共识是:这是一个糟糕的主意,需要大量的(App Store法律)黑客来完成,而且还没有变得太漂亮了(状态栏,例如,拧起来)。 你会注意到在Skype应用程序中,当你进入即时通讯部分,旋转到风景,并回来,用户界面“alignment”,或立即重新加载。

这不是一个好的用户体验,我build议重新考虑一下devise,以便更符合苹果的build议。

如果我正确地得到了你想在某些条件下改变设备的方向。

[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationPortrait animated:NO]; 

使用上面的行设置你自己的方向,只要把这条线放在if条件中。 条件是取决于你。

谢谢!!

写这行,然后推viewController,它只支持肖像从landscapeViewController

 [appdel.navigationController.view removeFromSuperview];// This navcontroller used with rootviewcontroller [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]; [ [UIApplication sharedApplication].self.delegate.window addSubview:appdel.navigationController.view]; self.navigationController.navigationBar.hidden=NO; 

这是一个解决scheme。 您可以为pipe理视图控制器方向的UINavigationController添加一个类别。 见下面的代码:

 @interface UINavigationController (MyViewOrientations) @end @implemetation UINavigationController (MyViewOrientations) - (BOOL)supportLandscapeModeForViewController:(UIViewController *)controller { return [controller isKindOfClass:[LandscapeSupportViewController class]] } - (NSUInteger)supportedInterfaceOrientation { UIViewController *controller = [self visibleViewController]; NSUInteger orientationMasks = UIInterfaceOrientationMaskPortrait if([self supportLandscapeModeForViewController:controller]) { orientationMasks |= UIInterfaceOrientationMaskLandscapeLeft; orientationMasks |= UIInterfaceOrientationMaskLandscapeRight; } return orientationMasks; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { UIViewController *controller = [self visibleViewController]; if([self supportLandscapeModeForViewController:controller]) { return UIInterfaceOrientationLandscapeLeft; // Your call } else { return UIInterfaceOrientationPortrait; } } - (BOOL)shouldAutorotate { UIViewController *controller = [self visibleViewController]; return [self supportLandscapeModeForViewController:controller]; } @end 

如果情况更复杂,不同的观点支持不同的方向。 您可以在视图控制器中覆盖“supportedInterfaceOrientation”,“preferredInterfaceOrientationForPresentation”,“shouldAutorotate”,并使用“visibleViewController”从UINavigationController类别代码中委托调用。