当前页面的rootVC 为一个nav 类型的控制器 ,要使其中单个页面可以旋转,需要自定义一个navigationController,然后在其中重写以下方法:
- (BOOL)shouldAutorotate
{
returnYES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
for (UIViewController *viewControllerinself.viewControllers) {
if ([viewControllerisKindOfClass:[LandscapeViewControllerclass]]) { //LandscapeViewController为需要有横屏功能的控制器
returnUIInterfaceOrientationMaskAllButUpsideDown;
}
}
returnUIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
returnUIInterfaceOrientationPortrait;
}
现在我们已经可以将单个页面进行横屏显示了,但是这样写会出现一个问题,那就是若当前页面横屏返回前一个页面时,前一个页面也成了横屏了,这时我们需要在前一个页面重写以下方法:
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
returnUIInterfaceOrientationMaskPortrait;
}
不对之处,欢迎指正。