一、使用场景概述
-  一种是在present出来的vc中打开横竖屏 
-  固定只有一个方向(横屏的方向) 
-  可根据重力感应进行横竖屏 
-  某个特定的push出来的vc中打开横竖屏(只能根据重力感应横竖屏,不能设置强制的方向) 
二、具体代码解释
-  要打开横竖屏功能需要打开开关同时设置ViewController的三个方法(必须要设置) 
-  然后需要注意固定一个方向显示时和根据重力感应时的shouldAutorotate的返回值是不一样的 
-  需要注意在离开vc时一定要关闭横竖屏,否则会导致整个APP显示错乱 
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    ALLOWROTATION
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    CLOSEROTATION
}
- (BOOL)shouldAutorotate{
    return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationPortrait;
}
三、重点在这
- 详细的demo地址,点我









