iOS6.0旋转兼容的那点事

移动开发 iOS
在iOS 6.0之前我们都是使用shouldAutorotateToInterfaceOrientation方法来控制视图、状态栏的旋转,但是iOS 6.0及以后就要使用supportedInterfaceOrientations方法来控制旋转了。

这两天问答系统里,问ios横竖屏切换、还有状态栏旋转的问题有点多,来些小心得,希望遇到的人少走弯路;
先贴官方说明:
iOS 6.0 Release Notes:
Autorotation is changing in iOS 6. In iOS 6, the shouldAutorotateToInterfaceOrientation: method 
of UIViewController is deprecated.In its place, you should use the supportedInterfaceOrientationsForWindow: 
and shouldAutorotate methods.

在iOS 6.0之前我们都是使用shouldAutorotateToInterfaceOrientation方法来控制视图、状态栏的旋转,但是iOS 6.0及以后
就要使用supportedInterfaceOrientations方法来控制旋转了;
所以向iOS 6.0兼容的需要手动添加supportedInterfaceOrientations 方法,来控制视图和
状态栏的旋转,还有两点需要说明:
1、在iOS 6.0之前,控制旋转的代码,无需和plist的中的Supported interface orientations一一对应,举个例子:
plist的Supported interface orientations选项中支持,Portrait(bottom home button)、Landscape(right home button),无Landscape(left home button)
方法shouldAutorotateToInterfaceOrientation中强制支持UIInterfaceOrientationLandscapeLeft编译执行没有任何问题,
但是在iOS 6.0中,如果在supportedInterfaceOrientations中添加UIInterfaceOrientationMaskLandscapeLeft编译正常,
运行过程中,左旋转程序就会异常退出;所以程序支持旋转的,代码与plist一定要保持一致;
2、在Xcode 4.5之前旋转支持的是
UIInterfaceOrientationLandscapeLeft  
 UIInterfaceOrientationLandscapeRight
UIInterfaceOrientationPortrait              
 UIInterfaceOrientationPortraitUpsideDown

而Xcode 4.5 GM Seed及Xcode 4.5.1旋转支持的是(多了个All,还有Mask的修饰,Xcode 4.5之前是不识别的)
UIInterfaceOrientationMaskAll      
UIInterfaceOrientationMaskLandscapeLeft
UIInterfaceOrientationMaskLandscapeRight        
UIInterfaceOrientationMaskPortrait
UIInterfaceOrientationMaskPortraitUpsideDown

责任编辑:闫佳明 来源: oschina
相关推荐

2011-04-14 14:23:06

软件测试测试

2018-03-15 15:12:00

润乾报表集成

2012-02-22 09:32:58

云计算微软Azure

2013-10-12 13:26:08

设计加载

2015-09-01 15:12:45

JavaHashMap那点事

2018-04-02 15:10:17

ToastSnackbarAndroid

2023-12-21 20:53:15

2011-05-25 19:37:47

2021-07-30 07:28:15

Kafka消息引擎

2011-08-31 10:15:48

桌面管理软件

2009-07-03 14:16:30

JSP Servlet

2010-08-10 15:08:17

UPS电源评测

2013-04-28 09:50:02

PHPMySQL

2012-06-11 15:02:53

ASP.NET

2015-08-07 15:39:26

仿微信语音界面源码

2011-02-22 09:47:58

WatchStor 征

2012-10-08 12:59:01

iOS 6.0开发框架功能更新

2019-07-01 14:55:44

应用安全web安全渗透测试

2018-10-22 13:34:24

SD-WAN运维网络

2010-07-22 10:07:01

SharePoint
点赞
收藏

51CTO技术栈公众号