转自:http://blog.csdn.net/wudizhukk/article/details/8674393

获得当前屏幕方向

self.interfaceOrientation或[[UIApplication sharedApplication] statusBarOrientation]

if (self.interfaceOrientation==UIDeviceOrientationLandscapeRight) {

XXOO

}

不旋转,保持竖屏

//iOS 5-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
        return(toInterfaceOrientation ==UIInterfaceOrientationPortrait);}//iOS 6-(BOOL)shouldAutorotate
{
        return NO;}-(NSUInteger)supportedInterfaceOrientations
{
        returnUIInterfaceOrientationMaskPortrait;}-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
        returnUIInterfaceOrientationPortrait;}

始终保持横屏

//iOS 5-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
        return(toInterfaceOrientation ==self.preferredInterfaceOrientationForPresentation);}//iOS 6-(BOOL) shouldAutorotate
{
        return YES;}-(NSUInteger)supportedInterfaceOrientations
{
        returnUIInterfaceOrientationMaskLandscapeRight;}-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
        returnUIInterfaceOrientationLandscapeRight;}

在使用UINavigationController时发现,无论怎么设置上面方法的返回,都无法控制UINavigationController的旋转,这似乎是iOS的一个bug。但无论如何,以下是stackflow上面的一个解决方法

 1 @implementation UINavigationController (Rotation_IOS6)
2 -(BOOL)shouldAutorotate {
3 return [[self.viewControllers lastObject] shouldAutorotate];
4 }
5
6 -(NSUInteger)supportedInterfaceOrientations {
7 return [[self.viewControllers lastObject] supportedInterfaceOrientations];
8 }
9
10 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
11 return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
12 }
13 @end

屏幕旋转方法调用流程

要翻转的时候,首先响应的方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

return YES则支持翻转,NO则不支持。

紧接着

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

被调用。这个方法是发生在翻转开始之前。一般用来禁用某些控件或者停止某些正在进行的活动,比如停止视频播放。
再来是

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

这个方法发生在翻转的过程中,一般用来定制翻转后各个控件的位置、大小等。可以用另外两个方法来代替:willAnimateFirstHalfOfRotationToInterfaceOrientation:duration:   和  willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:

最后调用的是

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

这个方法发生在整个翻转完成之后。一般用来重新启用某些控件或者继续翻转之前被暂停的活动,比如继续视频播放

IOS疯狂基础之屏幕旋转控制,获得当前方向(转)的更多相关文章

  1. IOS疯狂基础之模态显示PresentModalViewController(转)

    转自:http://blog.csdn.net/wudizhukk/article/details/8553554 -(void)buttonDown:(id)sender{ ViewTwo *two ...

  2. IOS 疯狂基础之 页面间跳转

    常用的就两种 一种通过导航,一种直接跳 第一种 直接跳转 思路大致就是new一个目的页面,然后设置下页面跳转动画 中间还可以做点目的页面的数据初始化: ValueInputView *valueVie ...

  3. IOS疯狂基础之观察者模式

    转自:http://blog.csdn.net/wudizhukk/article/details/8981535 一.KVO Key-Value Observing,它提供一种机制,当指定的对象的属 ...

  4. IOS开发基础知识碎片-导航

    1:IOS开发基础知识--碎片1 a:NSString与NSInteger的互换 b:Objective-c中集合里面不能存放基础类型,比如int string float等,只能把它们转化成对象才可 ...

  5. iOS系列 基础篇 05 视图鼻祖 - UIView

    iOS系列 基础篇 05 视图鼻祖 - UIView 目录: UIView“家族” 应用界面的构建层次 视图分类 最后 在Cocoa和Cocoa Touch框架中,“根”类时NSObject类.同样, ...

  6. iOS系列 基础篇 08 文本与键盘

    iOS系列 基础篇 08 文本与键盘 目录: 1. 扯扯犊子 2. TextField 3. TextView 4. 键盘的打开和关闭 5. 打开/关闭键盘的通知 6. 键盘的种类 7. 最后再扯两句 ...

  7. iOS系列 基础篇 09 开关、滑块和分段控件

    iOS系列 基础篇 09 开关.滑块和分段控件 目录: 案例说明 开关控件Switch 滑块控件Slider 分段控件Segmented Control 1. 案例说明 开关控件(Switch).滑块 ...

  8. IOS开发基础环境搭建

    一.目的 本文的目的是windows下IOS开发基础环境搭建做了对应的介绍,大家可根据文档步骤进行mac环境部署: 二.安装虚拟机 下载虚拟机安装文件绿色版,点击如下文件安装 获取安装包:       ...

  9. 【1】windows下IOS开发基础环境搭建

    一.目的 本文的目的是windows下IOS开发基础环境搭建做了对应的介绍,大家可根据文档步骤进行mac环境部署: 二.安装虚拟机 下载虚拟机安装文件绿色版,点击如下文件安装 获取安装包:       ...

随机推荐

  1. NoiseSystem数据库设计心得-洋芋好想飞

    团队:洋芋好想飞 成员:乔祥硕 石高飞 杨慧慧 梁家豪 潘景渝 整理:乔祥硕 PM乔祥硕: 10月25日14:30到17:30,10月27日14:30到17:30,11月1日14:30到17:30,这 ...

  2. [browser window窗口大小 算是screen补充吧]主要因为移动IE游览器 写了个兼容

    先上图吧 来上代码 console.log(window.outerWidth + '--' + window.outerHeight);//只读的整数,声明了整个窗口的XY //IE 不支持此属性, ...

  3. Dynamics 365 CE Update消息PostOperation阶段Image的尝试

    我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...

  4. c程序内存检测工具 - Valgrind

    常用C程序内存泄露检测工具 https://blog.csdn.net/u012662731/article/details/78652651

  5. Export Receives The Errors ORA-1555 ORA-22924 ORA-1578 ORA-22922 (Doc ID 787004.1)

    Export Receives The Errors ORA-1555 ORA-22924 ORA-1578 ORA-22922 (Doc ID 787004.1) APPLIES TO: Oracl ...

  6. tornado的IOLoop.instance()方法和IOLoop.current()方法区别

    在使用tornado时,经常有人疑惑IOLoop.instance()方法和IOLoop.current()方法的区别是什么. IOLoop.instance() 返回一个全局 IOLoop实例. 大 ...

  7. Linux设置免密登陆

    生成秘钥 ssh-keygen -t rsa -C "XX@qq.com",然后一路回车就行 生成之后会在用户的根目录生成一个 ".ssh"的文件夹 进入&qu ...

  8. linux,xshell命令

     一. linux  1.Linux发行版 <1> 常见的发行版本如下: Ubuntu Redhat Fedora openSUSE Linux Mint Debian Manjaro M ...

  9. 去掉Oracle数据库中字段值前后空格

    发现oracle字段钟包含了空格,可能是前空格,也可能是后空格,因为是历史数据,需要特殊处理.但是中间的空格可能是一些特殊人员的姓名含有,这种情况不能处理.所以我们只需要处理前后空格即可.使用如下sq ...

  10. Python程序中的线程操作-线程队列

    目录 一.线程队列 二.先进先出 三.后进先出 四.存储数据时可设置优先级的队列 4.1 优先级队列 4.2 更多方法说明 一.线程队列 queue队列:使用import queue,用法与进程Que ...