iOS 开发之需要的页面只支持竖屏

好久没有写过了呢,今天就来记录一下项目中遇到的一个小问题:个别页面只支持横屏或是竖屏,其他页面支持横竖屏。
参考博客:http://www.cnblogs.com/lear/p/5051818.html
我这边是带导航栏的,实现也挺简单的,直接上代码吧
创建导航栏的类目,并在.m文件实现下面的方法

 //是否允许转屏
- (BOOL)shouldAutorotate
{
    return [self.topViewController shouldAutorotate];
}
//viewController所支持的全部旋转方向
- (NSUInteger)supportedInterfaceOrientations
{
    return [self.topViewController supportedInterfaceOrientations];
}
  //viewController初始显示的方向
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [self.topViewController preferredInterfaceOrientationForPresentation];
}

下面在需要只支持竖屏的页面再重写一遍上面的方法就行了,如下:

- (BOOL)shouldAutorotate{
    //不允许转屏
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    //viewController所支持的全部旋转方向
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    //viewController初始显示的方向
    return UIInterfaceOrientationPortrait;
}

这样的话就实现其余页面支持横竖屏,需要只支持竖屏的页面只支持竖屏了,是不是很简单!

你可能感兴趣的:(iOS 开发之需要的页面只支持竖屏)