【问题标题】:cocos2d orientation issues in ios<= 6ios<= 6 中的 cocos2d 方向问题
【发布时间】:2013-01-15 08:39:15
【问题描述】:

我开发的游戏仅支持 ios 4.3 以上设备的横向模式。 该应用程序在 ios 6 设备上实现了 gamecenter 并在测试期间崩溃,因为 gamecenter 登录屏幕不支持 ios 6 中的横向模式。 所以我修复了将以下代码添加到 appdelegate.m 的问题并开始工作,但现在应用程序在 ios6(ios5 等)以下的设备上显示完全有线(显示纵向倒置)

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        return UIInterfaceOrientationMaskAll;
    else // iphone
        return UIInterfaceOrientationMaskAllButUpsideDown;
}

使用 代码:4.5 cocos2d v1.0.1

请帮我解决这个问题

【问题讨论】:

    标签: iphone ios objective-c cocos2d-iphone


    【解决方案1】:

    在你的项目中添加给定的类

    GKMatchmakerViewController-LandscapeOnly.h
    
    #import <Foundation/Foundation.h>
    #import <GameKit/GameKit.h>
    
    @interface GKMatchmakerViewController(LandscapeOnly)
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
    @end
    
    GKMatchmakerViewController-LandscapeOnly.m
    
    
    #import "GKMatchmakerViewController-LandscapeOnly.h"
    
    @implementation GKMatchmakerViewController (LandscapeOnly)
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
        return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) );
    }
    
    @end
    

    【讨论】:

    • 你能解释一下它是如何工作的吗?我需要在 appdelegate 或 rootviewcontroller 中调用这个类吗?
    • 你只需创建这个文件并在 GCHelper 类中调用 GKMatchmakerViewController
    • 如果有问题再告诉我
    • 抱歉回复晚了。不幸的是,这个解决方案无法解决问题。但是我能够通过更改与 appdelegate 中的方向相关的代码来解决这个问题。谢谢
    • 好的,但我在当前游戏中使用此代码,它工作正常。
    【解决方案2】:

    替换这行代码[window addSubview: viewController.view];在 AppDelegate.m 中有以下一项

    //************************************************************************
        NSString *reqSysVer = @"6.0";
        NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
        if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
        {
            [window setRootViewController:viewController];
        } else
        {
            [window addSubview: viewController.view];
        }
        //************************************************************************
    

    并在 RootViewController.m 中添加以下代码

    ///////********************************/////////
    
    // For ios6, use supportedInterfaceOrientations & shouldAutorotate instead of shouldAutorotateToInterfaceOrientation
    
    - (NSUInteger) supportedInterfaceOrientations{
        return UIInterfaceOrientationMaskLandscape;
    }
    
    - (BOOL) shouldAutorotate {
        return YES;
    }
    
    ///////********************************/////////
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-30
      • 2012-09-12
      • 2013-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多