iOS屏幕旋转总结

来源:互联网 发布:淘宝网购物天猫 编辑:程序博客网 时间:2024/06/06 14:16

本文介绍控制iOS应用屏幕旋转的体系流程及相关API(开发环境为Xcode5)。


一、设置application的orientation

方法1: 最直观的方法。设置工程的target --> General-->Deployment Info --> Device Orientation,这里的设置会反映到-info.plist文件中。

方法2:实际与方法1一样。在-info.plist中添加Key:Supported interface orientations,value就是要支持的orientation。

方法3:在AppDelegate.m中重写- (NSUInteger)application:  supportedInterfaceOrientationsForWindow:方法。


二、设置某个viewcontroller的方向

1.设置viewcontroller显示的初始方向:使用- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation方法。

方法说明:

(a)当某个viewcontroller支持过个方向时,你可以使用此方法确定一个初始显示的方向;

(b)当全屏展示一个viewcontroller时,系统会调用此方法;

(c)如果你不实现此方法,viewcontroller出现的的方向为系统的status bar的方向。


2.旋转总不能乱转吧,所以——

(1)旋转的开关:- (BOOL)shouldAutorotate方法。

(2)能够旋转到哪些方向?——使用-(NSUInteger)supportedInterfaceOrientations方法。

方法说明:

 (a)此方法仅当设备方向改变时调用,以决定是否旋转

 (b)调用的是topmostviewcontroller中的方法;

 (c)旋转的是windows以及viewcontroller;

 (d)仅当shouldAutorotate方法返回YES的时候起作用;

 (e)最终确定的方向是此方法的返回值与application的orientation交集。


over.


0 0
原创粉丝点击