转自: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. .net core 2.1 基于Jwt的登录认证

    1.新建一个.net core2.1 基于 api 的工程,引用Microsoft.AspNetCore.Authentication.JwtBearer 包 2.新建一个Token的实体类,一个Jw ...

  2. vue v-if和v-show的区别

    其中v-if依赖于控制DOM节点,而v-show是依赖于控制DOM节点的display属性. 当v-show传入的值为true时,对应DOM元素的display的值为block之类的,反之为false ...

  3. boostrap 学习笔记

    bootstrap : 是全球最受欢迎的前端组件库,用于开发响应式布局.移动设备优先的 WEB 项目. 用于项目样式的快速搭建,真的是..特别快.. 随便找两个cdn引用就能使用了. https:// ...

  4. Cesium专栏-空间分析之地形等高线(附源码下载)

    Cesium Cesium 是一款面向三维地球和地图的,世界级的JavaScript开源产品.它提供了基于JavaScript语言的开发包,方便用户快速搭建一款零插件的虚拟地球Web应用,并在性能,精 ...

  5. iOS sqlite ORM框架-LKDBHelper

    LKDBHelper 一个sqlite ORM(全自动操作数据库)框架. 线程安全.不再担心递归锁死的问题 安装要求 iOS 4.3+ 仅支持 ARC FMDB 添加到你的项目 如果你使用 Cocoa ...

  6. django之查询操作及开启事务

    目录 聚合查询 aggregate 聚合函数 分组查询 annotate F与Q查询 F查询 Q查询 ORM操作事务 django中开启事务 聚合查询 aggregate 操作外键字段管理数据的时候, ...

  7. add to explorer context menu需不需要勾选

    添加到鼠标右键菜单,添加以后,可以直接右键文件,直接选择这个软件打开选择的文件,建议勾选

  8. MyBatis中特殊符号的转义

    在MyBatis中遇到特殊符号时有两种转义方式: 第一种 描述 空格 小于 大于 小于等于 大于等于 与 单引号 双引号 原符号 < > <= >= & ' " ...

  9. CodeForces-1217D (拓扑排序/dfs 判环)

    题意 https://vjudge.net/problem/CodeForces-1217D 请给一个有向图着色,使得没有一个环只有一个颜色,您需要最小化使用颜色的数量. 思路 因为是有向图,每个环两 ...

  10. Gaussian field consensus论文解读及MATLAB实现

    Gaussian field consensus论文解读及MATLAB实现 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 一.Introduction ...