【问题标题】:How to get app to be in landscape orientation in cocos2d 2.0如何让应用程序在 cocos2d 2.0 中处于横向
【发布时间】:2012-08-03 16:31:06
【问题描述】:

(对不起,我不能包含图片。我没有足够高的代表,所以我只提供了图片的链接)

正如标题所说,我的应用在横向模式下遇到问题。我希望整个应用程序处于横向模式,所以我在目标摘要中只选择了横向左侧和横向右侧。我也放了这个:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return UIInterfaceOrientationIsLandscape(interfaceOrientation);
    }

在我的 AppDelegate.m 中。我还去了我的 info.plist 并将“初始界面方向设置为横向(左主页按钮)。但是我在模拟器和实际设备上的方向是错误的。这是我在故事板中的图片(我希望它看起来像)

http://imageshack.us/photo/my-images/836/iphoneimage2.png/

但这就是它在我的模拟器和设备上的样子

http://imageshack.us/photo/my-images/440/iphoneimage.png/

有谁知道如何解决这个问题?谢谢

【问题讨论】:

    标签: cocos2d-iphone orientation xcode4.3 uiinterfaceorientation


    【解决方案1】:

    编辑:如果你运行的是 Cocos2d 2.0 rc1 或 rc0a,那么shouldAutorotateToInterfaceOrientation: 方法应该放在 RootViewController.m 文件中。如果你运行的是 Cocos2d 2.0,shouldAutorotateToInterfaceOrientation: 应该放在 AppDelegate.m 文件中。

    如果您使用 Cocos2d 2.0 rc1 或 rc0a 中的模板之一来创建您的应用程序,则该方法已经在 RootViewController.m 中。

    如果您使用 Coco2d 2.0,该方法已经在 AppDelegate.m 中。

    您只需编辑该方法以仅返回您需要的所需方向。

    根据您使用的 Cocos2d 2.0 版本,编辑 RootViewController.m 或 AppDelegate.m 类中的方法,使其看起来像这样以适应两个横向方向:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return UIInterfaceOrientationIsLandscape(interfaceOrientation);
    }
    

    【讨论】:

    • 我没有 RootViewController.m 我有 AppDelegate、IntroLayer、MainMenu(UIViewController 的子类)、CCViewController(用于我的 cocos 游戏)、cocos2dViewController(CCViewController 的子类)和 GamePlay(即我的游戏的所有内容都在哪里)。
    • 如果你的应用是使用 Cocos2d 2.0 附带的模板之一制作的,那么你将拥有一个 RootViewController.m 类。但是,如果您没有,那么无论您的应用程序应该具有的主 ViewController 都将是添加该代码的那个。在 AppDelegate 中,应用程序主/主视图控制器是您的 glView 添加到的视图控制器,然后将相同的视图控制器添加到应用程序主 UIWindow。您的 AppDelegate 可能没有正确设置 Cocos2d 以使用 viewController,但 Apple 建议您使用 viewController。
    • 我确实为我的应用使用了 cocos2d 2.0 模板,但它只从 AppDelegate、HelloWorldLayer 和 IntroLayer 开始
    • 抱歉,我刚刚注意到在 Coco2d 2.0 rc1 中它与我描述的一样,但在 Cocos2d 2.0 中,RootViewController 类被删除并替换为 CCDirector 是 CC_VIEWCONTROLLER 的子类,并且在 ios 上定义了 CC_VIEWCONTROLLER成为 UIViewController。导演确实将 AppDelegate 设置为 ViewController 委托,因此您在 AppDelegate 中的 shouldAutorotateToInterfaceOrientation: 方法放置是正确的。
    • 您是否有一个包含 Cocos2d 内容的 Cocos2d 场景,您可以运行它来查看它是否可以正确旋转到横向?我猜您的问题与您在横向使用情节提要定义主菜单视图控制器有关。
    猜你喜欢
    • 1970-01-01
    • 2013-11-26
    • 1970-01-01
    • 2015-03-24
    • 1970-01-01
    • 1970-01-01
    • 2016-02-08
    • 1970-01-01
    • 2015-04-21
    相关资源
    最近更新 更多