IOS iOS5和iOS6横竖屏同时支持

本文介绍如何在iOS6中实现屏幕旋转支持,并提供了解决GameCenter登录界面仅支持竖屏显示的问题方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


iOS6下的 

1 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
2 {
3     return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);

// 可以修改为任何方向 

4 }

这个不会再被调用,取而代之的是这俩个组合:

1 - (BOOL)shouldAutorotate
2 {
3     return YES; //支持转屏
4 }
5  
6 - (NSUInteger)supportedInterfaceOrientations
7 {
8     return UIInterfaceOrientationMaskLandscape;

      // 这里返回哪个值,就看你想支持哪几个方向了。这里必须和plist文件里面的一致。

9 }

当然,为了保持对旧版本系统行为的兼容性,不要删掉不用的那个调用。另外还有一个这个preferred朝向也可以加上

1 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
2 {
3     return UIInterfaceOrientationLandscapeRight;
4 }

当我替换完这俩个操作后尝试运行app,发现会报如下的异常:
Terminating app due to uncaught exception ‘UIApplicationInvalidInterfaceOrientation’, reason: ‘Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES’

经查发现导致此异常的原因是app再info.plist中指定的屏幕朝向没有portrait,也就是只支持landscape横屏,但是app集成了 Game Center应用,而Game Center触发的登录界面只支持竖屏显示(这点有开发帐号的朋友可以到苹果官方开发论坛上看下,有个苹果官方人员发的证实贴,由于现阶段的NDA就不转 了),解决这个问题的方法就是再应用的delegate中加入如下回调:

1 - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
2 {
3     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
4         return UIInterfaceOrientationMaskAll;
5     else  /* iphone */
6         return UIInterfaceOrientationMaskAllButUpsideDown;
7 }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值