iOS6的旋屏控制技巧
在iOS5.1 和 之前的版本中, 我们通常利用 shouldAutorotateToInterfaceOrientation: 来单独控制某个UIViewController的旋屏方向支持,比如:
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
- }
但是在iOS6中,这个方法被废弃了,使用无效。
shouldAutorotateToInterfaceOrientation:
Returns a Boolean value indicating whether the view controller supports the specified orientation. (Deprecated in iOS 6.0. Override the supportedInterfaceOrientations andpreferredInterfaceOrientationForPresentation methods instead.)
实践后会发现,通过supportedInterfaceOrientations的单独控制是无法锁定屏幕的。
- -(NSUInteger)supportedInterfaceOrientations
- {
- return UIInterfaceOrientationMaskPortrait;
- }
多次实验后总结出控制屏幕旋转支持方向的方法如下:
子类化UINavigationController,增加方法
- - (BOOL)shouldAutorotate
- {
- return self.topViewController.shouldAutorotate;
- }
- - (NSUInteger)supportedInterfaceOrientations
- {
- return self.topViewController.supportedInterfaceOrientations;
- }
并且设定其为程序入口,或指定为 self.window.rootViewController
随后添加自己的view controller,如果想禁止某个view controller的旋屏:(支持全部版本的控制)
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
- }
- -(BOOL)shouldAutorotate
- {
- return NO;
- }
- -(NSUInteger)supportedInterfaceOrientations
- {
- return UIInterfaceOrientationMaskPortrait;
- }
如果想又开启某个view controller的全部方向旋屏支持:
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
- }
- -(NSUInteger)supportedInterfaceOrientations
- {
- return UIInterfaceOrientationMaskAllButUpsideDown;
- }
- -(BOOL)shouldAutorotate
- {
- return YES;
- }
从而实现了对每个view controller的单独控制。
顺便提一下,如果整个应用所有view controller都不支持旋屏,那么干脆:
- - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
- {
- return UIInterfaceOrientationMaskPortrait;
- }
下次再说说iOS6的内存控制吧
iOS6的旋屏控制技巧的更多相关文章
- ios 导航栏和旋屏
1,状态栏(UIStatusBar) http://my.oschina.net/shede333/blog/304560 2,visibleViewController和topViewControl ...
- iOS6以后的单个控制器横竖屏显示以及旋转屏控制技巧,附带iOS8以后显示电池状态栏
一.在应用中从竖屏模式强制转换为横屏模式 第一种方法:通过模态弹出视图的方式,使得特定ViewController坚持特定的interfaceOrientation(1)iOS6之后提供了这样一个方法 ...
- iOS 旋屏问题
今天突然想起来,以前的一个问题没有解决,就上网百度了一些方法,看到一篇文章,写的很详细,我就操作试试,结果还真的实现了功能,接下来我将重复他的结合我自己的测试,说一下iOS中的旋屏问题. 1.首先配置 ...
- 关于win10企业版在极域电子教室软件 v4.0 2015 豪华版的全屏控制下如何取得自由
注.可能因为系统和软件的缘故无法实现 背景 由于在听课过程过于自闭,于是想自己去网上搜点东西看下 于是 经过了一番乱搞 逐渐摸索出了现方法. 方案1: 大力出奇迹 由于电脑在刚刚进入的状态的时候有段时 ...
- UIImagePickerController在UIPopoverController中 旋屏问题
1弧度=180/π度1度=π/180弧度今天遇到了 一个问题.UIImagePickerController在UIPopoverController中 旋屏问题. 在查找了许多资料后方知,此乃iOS系 ...
- iOS旋屏
横竖屏切换,视图乱了怎么办? 首先,我们必须了解一下下列4种状态,它们被用来描述设备旋转方向: UIInterfaceOrientationLandscapeLeft 向左,即HOME键在右 UIIn ...
- iOS特殊界面旋屏设置的方法之一
1.AppDelegate.h @property (assign, nonatomic) BOOL allowRotation; 2.AppDelegate.m #pragma mark - 自动旋 ...
- android横竖屏控制
代码中设置activity屏幕为全屏,并设置横竖屏状态 getwindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowM ...
- IOS横竖屏控制与事件处理
公司App里面有个需求,即所有界面都是竖屏,且不允许横屏切换,唯独有一个图表界面允许横屏.那么,根据此需求处理如下: 首先,确保App本身应该允许转屏切换: 再次,我的App里面都是走UINaviga ...
随机推荐
- python学习笔记十三 JS,Dom(进阶篇)
JS介绍 JavaScript 是属于网络的脚本语言!JavaScript 被数百万计的网页用来改进设计.验证表单.检测浏览器.创建cookies,以及更多的应用:JavaScript 是因特网上最流 ...
- 【前端】互联网公司2014前端笔试面试题JavaScript篇(待续)
// 网上找的题目,自己做了下 /**************************** *1. 用js实现随机选取10–100之间的10个数字,存入一个数组,并排序 *************** ...
- (转)建站知识:域名/ 空间/ IP/ 端口之间的关系
先说域名解析吧,比如说你的域名是 www.sunnymould.com,这个域名对应着一个IP地址,域名解析就是把上面的域名转换成这个IP地址的过程,这样你就可以域名访问了上面地址上的内容了. 端口映 ...
- mac os 添加用户到组 命令
mac os 添加用户到组 命令 dscl localhost 进入组目录 cd /Local/Default/Groups 使用ls 你就可以看到所有的group,? /Local/Default/ ...
- Sprint(第二天11.15)
Sprint1第一阶段 1.类名:软件工程-第一阶段 2.时间:11.14-11.23 3.选题内容:点餐系统 4.团队博客地址:http://www.cnblogs.com/iamCarson/ 团 ...
- Install Google Pinyin on Ubuntu 14.04
Install Google Pinyin on Ubuntu 14.04 I've been spending more and more time on Ubuntu and I'm not us ...
- Java中的static关键字解析 转载
原文链接:http://www.cnblogs.com/dolphin0520/p/3799052.html Java中的static关键字解析 static关键字是很多朋友在编写代码和阅读代码时碰到 ...
- [php] php图表显示
使用jpgragh绘制php图表, 下载地址http://jpgraph.net/download/ 1> 服务器环境centos6.5, php5.0. 2> linux环境下需要配置j ...
- C++用PostMessage模拟按钮点击
有时我们可能会在某个程序中用到模拟按钮点击事件. 本文中的例子在MFC程序中调试通过,duilib的没试过,还需探索 不多说,上代码: #include "stdafx.h" #i ...
- Linux系统信息查看
转自:http://blog.chinaitlab.com/html/31/1365331-180901.html 查看redhat版本:cat /etc/redhat-release或者cat /e ...