IOS疯狂基础之屏幕旋转控制,获得当前方向(转)
转自: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疯狂基础之屏幕旋转控制,获得当前方向(转)的更多相关文章
- IOS疯狂基础之模态显示PresentModalViewController(转)
转自:http://blog.csdn.net/wudizhukk/article/details/8553554 -(void)buttonDown:(id)sender{ ViewTwo *two ...
- IOS 疯狂基础之 页面间跳转
常用的就两种 一种通过导航,一种直接跳 第一种 直接跳转 思路大致就是new一个目的页面,然后设置下页面跳转动画 中间还可以做点目的页面的数据初始化: ValueInputView *valueVie ...
- IOS疯狂基础之观察者模式
转自:http://blog.csdn.net/wudizhukk/article/details/8981535 一.KVO Key-Value Observing,它提供一种机制,当指定的对象的属 ...
- IOS开发基础知识碎片-导航
1:IOS开发基础知识--碎片1 a:NSString与NSInteger的互换 b:Objective-c中集合里面不能存放基础类型,比如int string float等,只能把它们转化成对象才可 ...
- iOS系列 基础篇 05 视图鼻祖 - UIView
iOS系列 基础篇 05 视图鼻祖 - UIView 目录: UIView“家族” 应用界面的构建层次 视图分类 最后 在Cocoa和Cocoa Touch框架中,“根”类时NSObject类.同样, ...
- iOS系列 基础篇 08 文本与键盘
iOS系列 基础篇 08 文本与键盘 目录: 1. 扯扯犊子 2. TextField 3. TextView 4. 键盘的打开和关闭 5. 打开/关闭键盘的通知 6. 键盘的种类 7. 最后再扯两句 ...
- iOS系列 基础篇 09 开关、滑块和分段控件
iOS系列 基础篇 09 开关.滑块和分段控件 目录: 案例说明 开关控件Switch 滑块控件Slider 分段控件Segmented Control 1. 案例说明 开关控件(Switch).滑块 ...
- IOS开发基础环境搭建
一.目的 本文的目的是windows下IOS开发基础环境搭建做了对应的介绍,大家可根据文档步骤进行mac环境部署: 二.安装虚拟机 下载虚拟机安装文件绿色版,点击如下文件安装 获取安装包: ...
- 【1】windows下IOS开发基础环境搭建
一.目的 本文的目的是windows下IOS开发基础环境搭建做了对应的介绍,大家可根据文档步骤进行mac环境部署: 二.安装虚拟机 下载虚拟机安装文件绿色版,点击如下文件安装 获取安装包: ...
随机推荐
- Thinkphp 5.1.24 parseKey缺陷导致聚合注入 分析
测试url: http://127.0.0.1/thinkphp/thinkphp_5.1.24/public/index.php/index/index/sqli2?id=2 控制器是获取id参数作 ...
- python是什么?python能做什么?
人生苦短,我用python. python是什么? Python是一个高层次的结合了解释性.编译性.互动性和面向对象的脚本语言. python语言有以下特点: 易于学习.Python有相对较少的关键字 ...
- 文件批量生成IO流读写
/// <summary> /// 生成文件的 /// </summary> /// <param name="calssName"></ ...
- 墙上你APP设计与实现
墙上你APP,听名字你们就应该可以想到是一个类似于表白墙吧,其实在做这个项目的时候我就是看到我们学校有一个专门工程墙,但是你找它发布消息表白或者找寻自己在学校掉了的饭卡或者身份证的时候,需要等它们同意 ...
- JQuery Deferred对象使用小结
场景描述 如下,打开页面时,获取默认选中的项目,同时也会初始化Combobox下拉框下拉列表数据 问题描述 获取默认选中项目及下拉列表的js函数位于common.js文件,类似如下: // 根据项目类 ...
- appium---App页面滑动
我们操作app的过程中都会进行页面滑动,那么这个过程通过python怎么实现呢? 如何滑动 大家都非常的清楚我们手动在app上是如何滑动的,然后自动化只是模仿了手工的方法去实现,我们通过一个图来分析 ...
- node.js守护进程问题的解决
最近自己写了一个node.js来读取redis数据,编写完成后按理来说加& 应该是有效的 nohup node redis.js & 但是每次关闭终端后这个进程就自动停止了,百度了下 ...
- CCPC2018-湖南全国邀请赛
传送门 A - Easy \(h\)-index 签到. Code /* * Author: heyuhhh * Created Time: 2019/10/29 11:58:23 */ #inclu ...
- OpenDaylight开发hello-world项目之代码框架搭建
OpenDaylight开发hello-world项目之开发环境搭建 OpenDaylight开发hello-world项目之开发工具安装 OpenDaylight开发hello-world项目之代码 ...
- __setattr__和__delattr__和__getattr__
目录 一.__setattr__ 二.__delattr__ 三. __getattr__ class Foo: x = 1 def __init__(self, y): self.y = y def ...