今天移植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插屏广告也是按照竖屏来显示,问题解决!