cocos2d2.1横屏切换竖屏程序崩溃问题

2023-05-21,,

cocos2d默认的是横屏,找到ios6.0横竖屏切换响应的函数

// Only valid for iOS 6+. NOT VALID for iOS 4 / 5.
-(NSUInteger)supportedInterfaceOrientations {
                                                                                                                                                                                                                                           
    // iPhone only
    if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )
        return UIInterfaceOrientationMaskPortrait;
                //return UIInterfaceOrientationMaskLandscape;
                                                                                                                                                                                                                                           
    // iPad only
    return UIInterfaceOrientationMaskPortrait;
    //return UIInterfaceOrientationMaskLandscape;
}

修改后,程序却意外的崩溃

百度了好久,找不到问题的所在。打开谷歌,问题一下子出来了。好吧,我在打广告。你们需要的广告。

在AppDelegate.m的AppController类下添加函数:

//解决ios6.0横竖屏切换程序崩溃问题
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskAll;
}

修改后,程序又意外的好了。

新手的悲哀啊,做事情都不知道为什么。

这难道就是传说中的bug。

《cocos2d2.1横屏切换竖屏程序崩溃问题.doc》

下载本文的Word格式文档,以方便收藏与打印。