1.让整个项目支持横屏
2.对于单个viewcontroller,直接实现下面的方法
- (BOOL)shouldAutorotate { //支持旋转
return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations { //支持的方向
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeRight;
}
3.如果是用navgationcontroller进行导航,iOS9貌似是默认支持旋转的,但为了支持iOS9以下,可以如下处理
a.创建一个navgationcontroller子类,在子类中实现上面的方法.
b.使用该子类作为导航控制器,这样每个viewcontroller都可以支持屏幕旋转了
这样做存在的问题:不能单独定制每个控制器的旋转方向
解决方法:在自定义的navigationcontroller里实现下面的方法
- (BOOL)shouldAutorotate { //支持旋转
return [self.topViewController shouldAutorotate];
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations { //支持的方向
return [self.topViewController supportedInterfaceOrientations];
}
这样的话,对于特定的viewcontroller,重写这些方法,返回自己想要支持的屏幕方向即可