iOS中关于shouldAutorotate(屏幕旋转的问题);
在这之前必须在你的Info里面配置你的支持方向信息:

我们的项目需要在个别的menuController里面是需要旋转,有的menuController是不需要旋转。我就尝试写个demo看是不是能旋转,不旋转;在demo里面测试是OK的。当我进入工程里面,跟新如下代码,运行的时候发现是错误的。本来是不旋转,可是还是可以旋转的,很郁闷。我就尝试在plist只支持竖屏,shouldAutorotate为YES,应该是旋转的,但是不旋转。我就在想为什么demo是可以的!我就开始翻资料

立马就找到了一个方法,如下

但是这个方法是在6之后被 NS_DEPRECATED_IOS(2_0, 6_0) 弃用了。加进controller里面各种尝试是不成功的。
后来找到了下面的连接,上面是说是跟你的tabbarController和navigationController有关系的。也就是你程序一开始的入口是谁控制的(你的工程的根试图控制器)!我在我的根试图控制器加上 图1的代码之后测试是成功的!
但是想在他的menuController里面不支持旋转的的时候,shouldAutorotate为NO,只支持竖屏的时候,他还是可以旋转的。但是我如果是模态推出用navigationController控制的时候shouldAutorotate为NO,只支持竖屏,是OK的。很是郁闷网上查了各种方法,没有找到相应的结果。我目前就是需要旋转的就用单独的navigationController去控制,不明白是哪里写错了还是没有看到相关的API。希望可以有人做到,因为项目进度表的原因,暂时就想这样写了。等待项目完成或者不加班的时候,再重新整理一下关于iOS屏幕旋转的问题!如果你有更好的解决方法,可以密我哦!我的邮箱maomaoxiansheng@outlook.com 、maomaoxiansheng@gmail.com,谢谢了!
参考 :
http://blog.csdn.net/totogogo/article/details/8002173
http://www.cocoachina.com/bbs/read.php?tid-116091.html
http://stackoverflow.com/questions/26503423/shouldautorotate-behavior-in-ios-8
http://blog.sina.com.cn/s/blog_6c9f384f0101538v.html
下面的是补充,上面这样写的有时候是有问题的,我们测试出来的伪BUG,当你的手机不是竖屏的时候启动应用程序,你的启动页面是横屏的,到了里面因为设置了有的是横屏有的是竖屏,就会出现很大的问题,后来我们在targets -> General -> Deployment Info或者plist里面的配置支持竖屏,在你的AppDelegate里面,用代码去控制。

然后在你想竖屏想横屏的地方写上相应的横竖屏的代码就可以了!
上面写得不够清楚,在模态推出之后发现有时候不管用,我在看API的时候也没有看到要注意的地方。后来发现在ViewController的shouldAutorotate要在View出现之前调用才会管用。而且这个方法没有set方法。创建一个继承UINavigationController的类


然后再模态推出的时候

之后在这个listVC里面写上

UITabBarController



祝大家,编码愉快,永不BUG。多锻炼身体哦。
iOS学习的地方还是很多的!加油!
网友评论
NSNumber * value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
让他竖起来。这个你掌控一下。
这个方法可以