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

相信大家都知道,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类型的,我之前就是因为把这两个类型搞混了,所以才费了半天劲最终找到问题的原因。希望对大家有所帮助。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值