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 ...
随机推荐
- 关于img 403 forbidden的一些思考
网页中经常需要显示图片给用户看,对网站本身来说有的图片是从本地图片服务器来的,但是一旦数量多了以后,磁盘空间又是一个问题. 所以有时就希望显示其他网站的Image,直接把其他网站的图片显示在我的网站上 ...
- C#网络爬虫
CronMaker is a utility which helps you to build cron expressions. CronMaker uses Quartz open source ...
- LeetCode----326. Power of Three(Java)
package isPowerOfThree326; /* Given an integer, write a function to determine if it is a power of th ...
- C++string中有关大小和容量的函数浅析
1.length()与size() length是因为沿用C语言的习惯而保留下来的,string类最初只有length,引入STL之后,为了兼容又加入了size,它是作为STL容器的属性存在的,便于符 ...
- 招聘一个靠谱的 iOS
近一年内陆续面试了不少人了,从面试者到面试官的转变让我对 iOS 招聘有了更多的感受.经过了前段时间的一大波面试,我们终于找到了志同道合的小伙伴,面试也暂时告一段落了.总结下面试人过程中的感受,你也可 ...
- SQL Server 2012 管理新特性:AlwaysOn【转】
http://jimshu.blog.51cto.com/3171847/871169 见超链接
- html5 drag and drop
注:链接.图片默认是draggable的. mousemove在整个拖放的过程中不会被触发. dragStart设置: e.dataTransfer.effectAllowed = "mov ...
- 原生cookie
出于浏览器的安全性限制,从WEB应用程序中访问用户本地文件系统是有许多限制的.但是WEB站点的开发人员可以使用cookie,将少量信息保存在用户本地硬盘的指定空间中. document对象的cooki ...
- exec函数族实例解析
exec函数族实例解析 fork()函数通过系统调用创建一个与原来进程(父进程)几乎完全相同的进程(子进程是父进程的副本,它将获得父进程数据空间.堆.栈等资源的副本.注意,子进程持有的是上述存储空间的 ...
- Asp.Net_单点登录
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...