您的位置:首页 > 移动开发 > IOS开发

<iOS开发兼容问题>关于IOS6和IOS5旋屏问题

2013-09-26 08:41 567 查看
http://blog.csdn.net/smking/article/details/8307590

相信大家都知道,ios6并不支持 shouldAutorotateToInterfaceOrientation 而强制打开项目的所有方向旋屏,会给一部分项目带来不便,

这个问题源于我以前的程序,都是在shouldAutorotateToInterfaceOrientation来判断当前的朝向,从而决定界面的布局,但是由于这个方法在ios6上不再调用,所以会出现ios6上无法旋转,且如果你之前的程序只支持横屏的话,在ios6上运行,会出现只能竖屏,并能以竖屏的方式显示以前横屏的内容。这时你会看到界面被切割,难看得你想骂人(如果你是用户的话)。

特别是rootController是横屏的情况下,如果纵向放置会出现明显的错位,这点在ios5会出现,ios6系统自动检测了,这里简单介绍下我的处理方法:

当然,在写这个博文时,我也在网上查过一些资料。
第一步:设置plist中的支持可以旋转的朝向。
第二步:在项目的AppDelegate文件加入
(其实我在试验中发现这步可有可无,当然也有可能我没有发现其重要性。)

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{

return UIInterfaceOrientationMaskAll;

}

第三步:在只需要横屏的控制器内添加

// ios5下的旋屏

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

return UIInterfaceOrientationIsLandscape(interfaceOrientation);

}

// ios6下的旋屏

-(BOOL)shouldAutorotate {

return YES;

}

-(NSUInteger)supportedInterfaceOrientations {

return UIInterfaceOrientationMaskLandscape;

}

在需要全方位旋屏的控制器内添加

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {

return YES;

}

-(NSUInteger)supportedInterfaceOrientations {

return UIInterfaceOrientationMaskAll;

}

-(BOOL)shouldAutorotate {

return YES;

}
说明:

1。如果没有在AppDelegate声明项目方向,在控制器旋屏情况下有时候会卡屏,选不过来,而且会有严重的错位。(但这个问题我目前还没有发现)

2。注意其中shouldAutorotateToInterfaceOrientation()中的参数是UIInterfaceOrientationPortrait,
而-(NSUInteger)supportedInterfaceOrientations {}, 返回的参数是

UIInterfaceOrientationMaskPortrait类型的,我之前就是因为把这两个类型搞混了,所以才费了半天劲最终找到问题的原因。希望对大家有所帮助。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: