原文地址:http://blog.csdn.net/littleSun_zheng/article/details/50748698
步骤1、
设置 targets——>general——>device Orientation
步骤2、
<1>在 AppDelegate.h 里面 加一个属性
@property (nonatomic,assign)BOOL allowRotation;//这个属性标识屏幕是否允许旋转
复制代码
<2>在 AppDelegate.m 里面
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if (self.allowRotation) {//当允许时,支持所有方向
return UIInterfaceOrientationMaskAll;
}
//否则 就只有竖屏
return UIInterfaceOrientationMaskPortrait;
}
复制代码
步骤3、 在你想要支持 旋转的控制器 需要导入#import "AppDelegate.h"
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
//改变AppDelegate的appdelegete.allowRotation属性
AppDelegate *appdelegete = (AppDelegate *)[UIApplication sharedApplication].delegate;
appdelegete.allowRotation = YES;
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
self.navigationController.navigationBarHidden = NO;
AppDelegate *appdelegete = (AppDelegate *)[UIApplication sharedApplication].delegate;
appdelegete.allowRotation = NO;
}
复制代码
步骤4、 但在横屏播放的状态下 直接返回上个控制器(pop)的时候. 发现那个控制器也是横屏的,假设上个控制器名字叫SimpleVC,在SimpleVC.m里添加
//屏幕方向操作
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
复制代码