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;

}

iOS项目旋转控制的更多相关文章

  1. 开源 iOS 项目分类索引大全 - 待整理

    开源 iOS 项目分类索引大全 GitHub 上大概600个开源 iOS 项目的分类和介绍,对于你挑选和使用开源项目应该有帮助 系统基础库 Category/Util sstoolkit 一套Cate ...

  2. ios项目里扒出来的json文件

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #000000 } p.p2 { margin: 0.0px 0. ...

  3. 现有iOS项目集成React Native过程记录

    在<Mac系统下React Native环境搭建>配置了RN的开发环境,然后,本文记录在现有iOS项目集成React Native的过程,官方推荐使用Cocoapods,项目一开始也是使用 ...

  4. iOS项目的本地化处理(多国语言)

    项目的本地化就是:iOS系统在不同语言环境下自动切换语言,从而实现一个app发布到全世界各个国家的AppStore上. 我们不仅仅需要在iOS项目中做本地化处理,在上架iOS APP的时候,也需要做对 ...

  5. 在Xcode 6 beta里编译Cocos2d-x iOS项目时失败

    转载 在Xcode 6 beta里编译Cocos2d-x iOS项目时可能会失败,提示如下错误: Undefined symbols for architecture i386: "_fwr ...

  6. phonegap创建的ios项目推送消息出现闪退现象

    使用phonegap创建的ios项目,推送消息时,当程序在前台运行或者在后台运行状态下,推送消息过来,可以解析并且跳转: 但是在程序从后台退出的状态下,当消息推送过来的时候,点击通知栏,打开程序,程序 ...

  7. MVVM 模式下iOS项目目录结构详细说明

    ➠更多技术干货请戳:听云博客 我们在做项目的时候,会经常用到各种设计模式,最常见的要数 MVC (模型,视图,控制器)了.但是,今天我们要说的是另一种设计模式——MVVM. 所以 MVVM 到底是什么 ...

  8. WinObjc - 使用iOS项目生成通用Windows应用

    Github上一周年的WinObjc项目最近发布了预览版本,终于等到了这一天.WinObjc项目就是Build 2015大会上微软宣布的Project IslandWood项目,致力于将iOS应用快速 ...

  9. iOS 项目中用到的一些开源库和第三方组件

    iOS 项目中用到的一些 iOS 开源库和第三方组件 分享一下我目前所在公司 iOS 项目中用到的一些 iOS 开源库和第三方组件, 感谢开源, 减少了我们的劳动力, 节约了我们大量的时间, 让我们有 ...

随机推荐

  1. sdk添加新的C文件编译出错

    make: *** 没有规则可以创建"test.elf"需要的目标"mike.c.o". 停止. 解决方法: 重新建立工程并且编译文件

  2. 使用SVN时出现的文件缺失问题

    使用SVN的童鞋们,可能有三种提交代码的方法: 第一种使用客户端(例如SVNX,CornerStone): 第二种使用Xcode提交(Source Control -> commit): 第三种 ...

  3. js进阶

    js在实例化对象后,可以对这个对象增加属性和属性值,并且还可以通过delete一元操作符来删除对象的属性. var o = new Object(); o.name = "langsin&q ...

  4. RSA For PHP

    最近和一保险公司对接接口,对方要求RSA加密,并给一个*.jks的文件,网上搜索一番均无答案,最后在谷歌上偶然看到一个人说需要转成.pem进行读取,折腾一番直接上代码: /** * 获取RSA加密ke ...

  5. iOS.ReactNative-3-about-viewmanager-uimanager-and-bridgemodule

    RCTViewManager and RCTUIManager 1. RCTViewManager 1.1 RCTViewManager 实现了接口RCTBridgeModule @interface ...

  6. 下拉tableView实现类似微信中带图的灰色背景

    UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(, -, ScreenWidth, )]; UIImageView *iconIma ...

  7. ChartServices Dev图形封装

    .工具类ChartServices using System; using System.Data; using System.Drawing; using DevExpress.XtraCharts ...

  8. 一个暂时无法理解的bug

    BUG bug的存在是不可避免的 一个静态变量,改成绝对地址之后可以生成静态页面.但是主页有一个用了静态变量的超链接就不能用, 最后我加了一个相对地址的静态变量,可以解决这个问题.

  9. Oracle sys和system用户、sysdba 和sysoper系统权限、sysdba和dba角色的区别

    sys和system用户区别 1)最重要的区别,存储的数据的重要性不同 sys所有oracle的数据字典的基表和视图都存放在sys用户中,这些基表和视图对于oracle的运行是至关重要的,由数据库自己 ...

  10. 菜单的隐藏&显示

    //还是先上万一老师的原代码 //隐藏与显示菜单Self.Menu := nil; {隐藏菜单} Self.Menu := MainMenu1; {显示菜单} //初一看到代码,我有点抓不到感觉的意思 ...