【Cocos2d-x】 关于IOS设置竖屏后,运行会报错的解决方法

本文介绍了解决Cocos2d项目在iOS设备上竖屏显示时遇到的问题,提供了两种有效的方法:一是修改RootViewController.mm文件中shouldAutorotate函数的返回值;二是更改info.plist文件中的Supportedinterfaceorientations设置。

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

今天移植Cocos2d项目的时候,运行的时候老是出现异常: Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'   。原因是:游戏需要竖屏显示,因为修改了RootViewController.mm里面的两个函数的返回值,分别是:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    //    return UIInterfaceOrientationIsLandscape( interfaceOrientation );// 横屏
    return UIInterfaceOrientationIsPortrait(interfaceOrientation);// 竖屏
}
- (NSUInteger) supportedInterfaceOrientations{
#ifdef __IPHONE_6_0
    //    return UIInterfaceOrientationMaskAllButUpsideDown;
    return UIInterfaceOrientationMaskPortrait; // 竖屏
#endif
}

出现了问题。解决这个问题有几个方法:

方法1:将RootViewController.mm里面的shouldAutorotate()函数返回值改成NO,如:

- (BOOL) shouldAutorotate {
    return NO;
}
改了之后可以正常运行,但是会有个问题,如果你的游戏里面有加了Chartboost插屏广告,该广告是横屏显示的,这显然不是我想要的。


方法2:修改ios目录下的info.plist文件。点开info.plist文件,找到“Supported interface orientations”这个设置项,修改Item0的值为:Portrait (bottom home button)。能正常运行程序,且Chartboost插屏广告也是按照竖屏来显示,问题解决!



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值