在iOS5.1 和 之前的版本中, 我们通常利用 shouldAutorotateToInterfaceOrientation: 来单独控制某个UIViewController的旋屏方向支持,比如:

  1. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  2. {
  3. return (interfaceOrientation == UIInterfaceOrientationPortrait);
  4. }

但是在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的单独控制是无法锁定屏幕的。

  1. -(NSUInteger)supportedInterfaceOrientations
  2. {
  3. return UIInterfaceOrientationMaskPortrait;
  4. }

多次实验后总结出控制屏幕旋转支持方向的方法如下:

子类化UINavigationController,增加方法

  1. - (BOOL)shouldAutorotate
  2. {
  3. return self.topViewController.shouldAutorotate;
  4. }
  5. - (NSUInteger)supportedInterfaceOrientations
  6. {
  7. return self.topViewController.supportedInterfaceOrientations;
  8. }

并且设定其为程序入口,或指定为 self.window.rootViewController

随后添加自己的view controller,如果想禁止某个view controller的旋屏:(支持全部版本的控制)

  1. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  2. {
  3. return (interfaceOrientation == UIInterfaceOrientationPortrait);
  4. }
  5. -(BOOL)shouldAutorotate
  6. {
  7. return NO;
  8. }
  9. -(NSUInteger)supportedInterfaceOrientations
  10. {
  11. return UIInterfaceOrientationMaskPortrait;
  12. }

如果想又开启某个view controller的全部方向旋屏支持:

  1. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  2. {
  3. return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
  4. }
  5. -(NSUInteger)supportedInterfaceOrientations
  6. {
  7. return UIInterfaceOrientationMaskAllButUpsideDown;
  8. }
  9. -(BOOL)shouldAutorotate
  10. {
  11. return YES;
  12. }

从而实现了对每个view controller的单独控制。

顺便提一下,如果整个应用所有view controller都不支持旋屏,那么干脆:

  1. - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
  2. {
  3. return UIInterfaceOrientationMaskPortrait;
  4. }

下次再说说iOS6的内存控制吧

iOS6的旋屏控制技巧的更多相关文章

  1. ios 导航栏和旋屏

    1,状态栏(UIStatusBar) http://my.oschina.net/shede333/blog/304560 2,visibleViewController和topViewControl ...

  2. iOS6以后的单个控制器横竖屏显示以及旋转屏控制技巧,附带iOS8以后显示电池状态栏

    一.在应用中从竖屏模式强制转换为横屏模式 第一种方法:通过模态弹出视图的方式,使得特定ViewController坚持特定的interfaceOrientation(1)iOS6之后提供了这样一个方法 ...

  3. iOS 旋屏问题

    今天突然想起来,以前的一个问题没有解决,就上网百度了一些方法,看到一篇文章,写的很详细,我就操作试试,结果还真的实现了功能,接下来我将重复他的结合我自己的测试,说一下iOS中的旋屏问题. 1.首先配置 ...

  4. 关于win10企业版在极域电子教室软件 v4.0 2015 豪华版的全屏控制下如何取得自由

    注.可能因为系统和软件的缘故无法实现 背景 由于在听课过程过于自闭,于是想自己去网上搜点东西看下 于是 经过了一番乱搞 逐渐摸索出了现方法. 方案1: 大力出奇迹 由于电脑在刚刚进入的状态的时候有段时 ...

  5. UIImagePickerController在UIPopoverController中 旋屏问题

    1弧度=180/π度1度=π/180弧度今天遇到了 一个问题.UIImagePickerController在UIPopoverController中 旋屏问题. 在查找了许多资料后方知,此乃iOS系 ...

  6. iOS旋屏

    横竖屏切换,视图乱了怎么办? 首先,我们必须了解一下下列4种状态,它们被用来描述设备旋转方向: UIInterfaceOrientationLandscapeLeft 向左,即HOME键在右 UIIn ...

  7. iOS特殊界面旋屏设置的方法之一

    1.AppDelegate.h @property (assign, nonatomic) BOOL allowRotation; 2.AppDelegate.m #pragma mark - 自动旋 ...

  8. android横竖屏控制

    代码中设置activity屏幕为全屏,并设置横竖屏状态 getwindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowM ...

  9. IOS横竖屏控制与事件处理

    公司App里面有个需求,即所有界面都是竖屏,且不允许横屏切换,唯独有一个图表界面允许横屏.那么,根据此需求处理如下: 首先,确保App本身应该允许转屏切换: 再次,我的App里面都是走UINaviga ...

随机推荐

  1. 打包app命令行

    $ cd myApp $ ionic platform add android $ ionic build android $ ionic emulate android

  2. Entity Framework 第九篇 关于自增列的事务处理

    如果一个表带有自增列的,那么在事务处理的过程中,如果抑制了提交,自增的序号就不会得到,如果我们需要得到那怎么办呢?可以临时提交,但是既然提交了就要考虑到事务回滚,否则无法满足数据的一致性 public ...

  3. Web页面速度测试工具

    开发框架的时间,想测试单例和多例下对性能的影响,找了下没有特别简单易用的测试工具. 估摸着搞了一个小工具. 针对.net Framework的2.0,3.5,4.0版本. WebHttpTest2.0 ...

  4. FreeSWITCH无法读取wav文件

    错误日志如下: -- :: Invalid file format [wav] /suite-espanola-op--leyenda.wav]! -- :: Can't open /usr/loca ...

  5. 删除DSO Change Log表数据

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  6. shockt通信

    目前为止,我们使用的最多网络协议还是tcp/ip网络.通常来说,我们习惯上称为tcp/ip协议栈.至于协议栈分成几层,有两种说法.一种是五层,一种是七层. 5.应用层    4.传输层    3.网络 ...

  7. python打怪之路【第二篇】:ImportError: No module named setuptools

    在python安装第三方模块时出现如下错误: python错误:ImportError: No module named setuptools这句错误提示的表面意思是:没有setuptools的模块, ...

  8. windows目录选择 文件选择 文件保存对话框

    打开文件对话框 const char pszFilter[] = _T("EXE File (*.txt)|*.txt|All Files (*.*)|*.*||"); CFile ...

  9. 超越线程池:Java并发并没有你想的那么糟糕

    转载: 超越线程池:Java并发并没有你想的那么糟糕

  10. canvas初体验之基本线条

    有的时候我们打开一些网站,可以看到背景是闪烁的星空或者是有一些可以与鼠标交互的线条等等,此酷炫的效果就是用到了html5的canvas效果. 首先来认识一下h5新增的标签的写法<canvas&g ...