iOS 6的rotation改变了很多。先来看看官方的描述  http://www.bgr.com/2012/08/06/ios-6-beta-4-change-log-now-available/

知识点:

*UIViewController的shouldAutorotateToInterfaceOrientation方法被deprecated。在ios6里,是使用supportedInterfaceOrientations and shouldAutorotate 2个方法来代替shouldAutorotateToInterfaceOrientation。注意:为了向后兼容iOS 4 and 5,还是需要在你的app里保留shouldAutorotateToInterfaceOrientation。

for ios 4 and 5, 如果没有重写shouldAutorotateToInterfaceOrientation,那么对于iphone来讲,by default是只支持portrait,不能旋转。

for ios 6, 如果没有重写shouldAutorotate and supportedInterfaceOrientations,by default, iphone则是"可以旋转,支持非upside down的方向",而ipad是"可以选择,支持所有方向"

example 1: for ios 4 and 5, iphone device, 若要"可以旋转,支持非upside down的方向",则可以在view controller里

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

example 2: for ios 6, iphone device, 若要“不能旋转,只支持portait",则可以在view controller里

  1. - (BOOL)shouldAutorotate
  2. {
  3. return NO;
  4. }

example 3: for ios 6, ipad device, 若要“可以旋转,只支持landscape",则可以在view controller里

  1. -(NSUInteger)supportedInterfaceOrientations{
  2. return UIInterfaceOrientationMaskLandscape;
  3. }
  4. - (BOOL)shouldAutorotate
  5. {
  6. return YES;
  7. }

* 在iOS 4 and 5,都是由具体的view controller来决定对应的view的orientation设置。而在iOS 6,则是由top-most  controller来决定view的orientation设置。

举个例子:你的app的rootViewController是navigation controller "nav", 在”nav"里的stack依次是:main view -> sub view > sub sub view,而main view里有一个button会present modal view "modal view".

那么for ios 4 and 5,在ipad里,如果你要上述view都仅支持横屏orientation,你需要在上面的main view, sub view, sub sub view, model view里都添加

  1. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  2. return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight);
  3. }

而对于iOS6, 由于是由top-most controller来设置orientation,因此你在main view, sub view, sub sub view里添加下面的代码是没有任何效果的,而应该是在nav controller里添加下列代码。而modal view则不是在nav container里,因此你也需要在modal
view里也添加下列代码。

  1. -(NSUInteger)supportedInterfaceOrientations{
  2. return UIInterfaceOrientationMaskLandscape;
  3. }
  4. - (BOOL)shouldAutorotate
  5. {
  6. return YES;
  7. }

注意:

*你需要自定义一个UINavigationController的子类for "nav controller",这样才可以添加上述代码。

* 和navigation controller类似,tab controller里的各个view的orientation设置应该放在tab controller里

for ios6的top-most controller决定orientation设置,导致这样一个问题:在 top-most controller里的views无法拥有不相同的orientation设置。例如:for iphone, 在nav controller里,你有main view, sub view and sub sub view,前2个都只能打竖,而sub sub view是用来播放video,可以打横打竖。那么在ios 4 and 5里可以通过在main view and sub view的shouldAutorotateToInterfaceOrientation里设置只能打竖,而在sub
sub view的shouldAutorotateToInterfaceOrientation设置打竖打横即可。而在ios 6里则无法实现这种效果,因为在main view, sub view and sub sub view的orientation设置是无效的,只能够在nav controller里设置。那么你可能想着用下列代码在nav controller里控制哪个view打竖,哪个view打横

  1. -(NSUInteger)supportedInterfaceOrientations{
  2. if([[self topViewController] isKindOfClass:[SubSubView class]])
  3. return UIInterfaceOrientationMaskAllButUpsideDown;
  4. else
  5. return UIInterfaceOrientationMaskPortrait;
  6. }

是的,这样可以使得在main view and sub view里无法打横,而sub sub view横竖都行。但问题来了,如果在sub sub view时打横,然后back to sub view,那么sub view是打横显示的!

目前想到的解决方法只能是把sub sub view脱离nav controller,以modal view方式来显示。这样就可以在modal view里设置打横打竖,而在nav controller里设置只打竖。

* 说了那么多,其实如果你的app的所有view的orientation的设置是统一的,那么你可以简单的在plist file里设置即可,不用添加上面的代码。而如果你添加了上面的代码,就会覆盖plist里orientation的设置。

* in iOS 6, 当view controller present时,不会call willRotateToInterfaceOrientation:duration:, willAnimateRotationToInterfaceOrientation:duration:, and didRotateFromInterfaceOrientation: methods,只有在发生rotate的时候才会call

iOS6 旋转的更多相关文章

  1. IOS6屏幕旋转详解(自动旋转、手动旋转、兼容IOS6之前系统)

    转自 http://blog.csdn.net/zzfsuiye/article/details/8251060 概述: 在iOS6之前的版本中,通常使用 shouldAutorotateToInte ...

  2. 【原】UI随设备旋转从iOS6到iOS8的适配策略

    - (void)statusBarOrientationChange:(NSNotification *)notification { WClassAndFunctionName; UIInterfa ...

  3. 【原】兼容IOS6以及旧版本的旋转处理方法,心得总结

    最近的项目需要频繁处理屏幕的旋转以及各控件的自适应坐标.IOS6出来之后,屏幕旋转的处理方法变得复杂很多.在查阅了很多资料以及动手测试之后,得出以下几点精简的体会: 对于IOS6.0以上版本: 1.如 ...

  4. ios6和ios7禁止屏幕旋转

    ios6和ios7禁止屏幕旋转 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOr ...

  5. 【精】iOS6 及其以上版本号自己主动旋转、手动强制旋转方案及布局适配

    1.布局适配方式 本文不讨论哪种布局适配方式最好.此处使用的是 Masonry 纯代码布局适配. (Masonry 底层就是 AutoLayout 的 NSLayoutConstraint) 2.iO ...

  6. UIInterfaceOrientation over iOS6 (应用旋转屏幕)

      typedef NS_ENUM(NSInteger, UIInterfaceOrientation) { UIInterfaceOrientationUnknown = UIDeviceOrien ...

  7. iOS----应用的旋转---Orientations

    此博文主要针对IOS应用, 是屏幕旋转相关问题的一个总结. 主要内容有: IOS5,6,7不同版的适配. 强制旋转和自动旋转. QQ : 1101819159 邮箱: GeekiVan@aliyun. ...

  8. iOS6、7、8、9新特性汇总和适配说明

    iOS6新特性 一.关于内存警告 ios6中废除了viewDidUnload,viewWillUnload这两个系统回调,收到内存警告时在didReceiveMemoryWarning中进行相关的处理 ...

  9. iOS6的旋屏控制技巧

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

随机推荐

  1. 基于jQuery的前端如何做到无伤迁移

    首先,解释一下我个人对前端无伤迁移的理解,即移动端和PC端使用同一套代码,或者说原本在PC端运行得很完美的代码,只要修改少许,就可以在移动端完美运行. 当然,大部分的公司会专门为移动端设计了一套,同时 ...

  2. for之Python vs C#

    class test(object): def rangetest(self): for i in range(2,0,-1): print i print i i=2 while i>0: p ...

  3. django随笔说明

    最近学习了vamei的快速Python教程,想着语法学了不用就要忘记,总要拿点东西来练练手,然后又开始学习Django,也算是顺势而为吧. 现在学Django,是跟着教程djangobook学的,内容 ...

  4. HTML 语义化

    语义化,让你的网页更好的被搜索引擎理解 要记住学习html标签过程中,主要注意两个方面的学习:标签的用途.标签在浏览器中的默认样式. 标签的用途:我们学习网页制作时,常常会听到一个词,语义化.那么什么 ...

  5. ListView学习小结

    ListView小结 ListView 是Android UI中十分重要的一个组件,在数据的显示上能有着十分灵活的表现,其使用也比较简单,一般包括以下几个要点: 1.  可以通过编写ListActiv ...

  6. poj3094---对字符串的处理

    #include <stdio.h> #include <stdlib.h> #include<string.h> int main() { ]; int len, ...

  7. uva 10163 - Storage Keepers(01背包)

    题目链接:10163 - Storage Keepers 题目大意:给出m为仓库的数量, 给出n为有守夜人的数量, 然后给出n个数值,为对应守夜人应付的酬劳,每个守夜人的能力与他需要的酬劳是相等的,并 ...

  8. Little Zu Chongzhi's Triangles

    Little Zu Chongzhi's Triangles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 ...

  9. n!的近似值 (stirling approximation)与 大O记法(big -O- notation)

    參考wiki: 1.n!的近似值 (stirling approximation) (中文) http://zh.wikipedia.org/wiki/%E6%96%AF%E7%89%B9%E9%9D ...

  10. 《think in python》学习-1

    高能提示:本文大量编程术语与释义,一些释义如有偏差恕不讨论. 纠结学Python 很久了,一年的纠结过程中慢慢的积累了一点对python的认知,但实际语法都未曾接触过,研究backbone的一个例子的 ...