转自: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. CAD简易口诀,保你一天就记住!零基础也能轻松学!CAD制图宝典!

    如何才能快速的学习CAD制图呢?不仅仅需要多练习,CAD口诀也是不能错过的哦!实用干货这一个就够了快点收藏起来! 1.创建直线的快捷方式是L+空格 2.创建圆的快捷方式是C+空格 3.创建圆弧的快捷方 ...

  2. PostgreSQL 表字段起别名

    使用Postgreq Sql 表字段起别名时注意要用双引号,使用单引号会出现语法错误,执行结果如图

  3. 微信两种签名算法MD5和HMAC-SHA256

    在做微信接口开发的过程中, 有时候发现会提示签名校验失败, 一模一样的签名逻辑就是有些接口跑步通, 找了一圈发现挺坑的; 原来是有些接口的signType签名类型有区别, 有些接口signType要求 ...

  4. React Native适配IPhoneX系列设备之<SafeAreaView />

    SafeAreaView的目的是在一个“安全”的可视区域内渲染内容.具体来说就是因为目前有 iPhone X 这样的带有“刘海”的全面屏设备,所以需要避免内容渲染到不可见的“刘海”范围内.本组件目前仅 ...

  5. Django注意知识点(二)

    Tinymce富文本 前台和后台的使用 一,后台 Admin 1. 于 settings.py 文件中修改 INSTALLED_APPS 2. 于 settings.py 文件中增添如下配置 # 富文 ...

  6. centos python3 的 卸载 删除

    卸载/删除python 3.4看到网上说慎用 apt-get remove和 yum remove ,因此不敢用此类命令用卸载了(以后阿里云服务器快过期不用了的时候可以试一下,看看系统是否会崩,哈哈) ...

  7. 转载:关于STM32硬件I2C读写EEPROM代码实现原理的理解与总结

    http://home.eeworld.com.cn/my/space-uid-716241-blogid-655190.html 一.I2C协议简介 I2C是两线式串行总线,用于连接微控制器及其外围 ...

  8. Linux Ctrl + Alt + Fx | (x = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)

    VMware Ubuntu中,按下 Ctrl + Alt + Fx | (x = 1...12),会出现不同的效果. 1. Ctrl + Alt + F1 ~ F6 Ctrl + Alt + F1 ~ ...

  9. 页面一刷新让文本框自动获取焦点-- 和自定义v-focus指令

    <body> <div id="app"> <input type="text" value="" id=&q ...

  10. Fiddler修改请求数据

    截断方法一: 在菜单中选择“Rules”->“Automatic Breakpoint”->“Before Requests”,这种方式会截断所有Request请求. 2.浏览器打开站点, ...