关于屏幕旋转

重新整理了下老博客
需求:全局主要是竖屏 个别界面需要横屏

一.前往TARGETS
找到TARGETS->General->点掉 Landscape

这边如果是做的通用版 需要把 Universal ipone ipad 挨个点开勾选一遍

二.前往plist
找到plist文件 在Supported interface 里面把横屏的Item点掉
3.找到需要设置横屏的控制器添加以下代码

<code>
-(BOOL)shouldAutorotate{
return NO;//有些情况这里是YES
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscapeRight;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationLandscapeRight;
}
</code>

这种方法的使用前提
1.当前viewControllerwindowrootViewController
2当前viewControllermodal模式的 即viewController是调用presentModalViewController而显示出来的

以上三个方法的补充说明:
-(BOOL)shouldAutorotate;
配置视图旋转设置
返回一个布尔值,该值指示视图控制器的内容是否��应该自动旋转。
如果为真内容应该旋转 否则假 默认值为真。
-(NSUInteger)supportedInterfaceOrientations;
返回控制器支持的所有视图方向
当用户更改设备方向,系统在根视图控制器或顶部视图控制器 调用此方法 模态出新的视图控制器。
如果视图控制器支持新的方向,窗口和视图控制器将旋转到新的方向。这个方法只有在视图控制器的��shouldAutorotate方法返回值为真时才会调用(这个表示疑惑 我就是在返回NO时调用的)。
重写这个方法 告诉视图控制器需要支持的所有方向。
一个视图控制器支持的��窗口方向的默认值 在iPad中设置为UIInterfaceOrientationMaskAll,在 iPhone中设置为UIInterfaceOrientationMaskAllButUpsideDown

没看明白 当视图控制器的支持方向和app支持的方向交叉时候 是怎么决定方向的
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;

Returns the interface orientation to use when presenting the view controller.

当使用模态视图控制器时 返回界面使用方向

The system calls this method when presenting the view controller full screen. You implement this method when your view controller supports two or more orientations but the content appears best in one of those orientations.

当模态到一个全屏视图控制器时系统调用此方法。你实现这个方法当 你的视图控制器支持两个或两个以上的方向 但是在显示内容最好的其中一个方向出现。

If your view controller implements this method, then when presented, its view is shown in the preferred orientation (although it can later be rotated to another supported rotation). If you do not implement this method, the system presents the view controller using the current orientation of the status bar.

如果你的视图控制器实现了该方法,然后模态视图时,其视图所示择优取向(尽管它以后可以旋转到另一个支持旋转)。如果你不实现这个方法,系统在模态到一个新的视图控制器时将使用当前状态栏的取向。

http://www.cnblogs.com/smileEvday/archive/2013/04/24/Rotate2.html 这篇写的不错 mark一下

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • iOS中关于shouldAutorotate(屏幕旋转的问题); 在这之前必须在你的Info里面配置你的支持方向信...
    燃烧的大叔阅读 44,661评论 40 63
  • /* UIViewController is a generic controller base class th...
    DanDanC阅读 1,862评论 0 2
  • 他们的国旗是蓝白相间。 他们的蓝天让人迷醉。 特别属于他们蓝色海洋。海岛爱琴海圣托里尼罗得岛。 还有我家留着蓝色头...
    自渡1117阅读 310评论 1 2
  • 夏日夜短昼渐长, 朝起沐浴向晨光。 金丝万缕意甚惬, 正是漫步好地方。
    無世真人阅读 267评论 2 12
  • 今天,是我的生日。之所以现在泡在简书上,是因为我突然醒了。记得迷迷糊糊的时候,还想着要和谁说说话来着,起码说个晚安...
    冷康康阅读 185评论 0 2