1

我有一些问题。我有一个即将完成开发的 cocos2d 游戏。但是,我遇到了一个问题,我需要在我的应用程序列表中启用纵向方向,以便游戏中心登录工作而不会引发 SIGABRT 错误。因此,一旦我从我的应用程序的构建摘要页面启用它(或将其添加到 info.plist 文件作为支持的方向),它就可以正常工作。但是,在我的游戏中,如果您转动 iPhone,它会在感应到您以这种方式转动时切换到纵向模式。我已经尝试从我的 AppDelegate.m 中弄乱 shouldAutorotateToInterfaceOrientation 方法,它根本没有被调用,也没有在任何时候被调用。我在方法中抛出了一个 NSLog 语句来确定它是否被调用,而事实并非如此。

所以,基本上我真正的问题是。当 Game Center 登录屏幕弹出时,我需要我的游戏保持横向模式。我如何在 Cocos2d 2.0 游戏中做到这一点?

我正在使用iOS6

4

3 回答 3

3

首先,确保应用在目标摘要中支持纵向和横向。

然后你需要创建一个新的根视图控制器来强制你进入横向模式,这样你的游戏就不会开始奇怪地旋转:

@implementation CUSTOM_RootViewController
-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL)shouldAutorotate {
    return YES;
}

@end

最后,在 AppDelegate.m 文件中,用新的导航控制器替换原来的导航控制器:

// Create a Navigation Controller with the Director
//navController_ = [[UINavigationController alloc] initWithRootViewController:director_];
navController_ = [[SMD_RootViewController alloc] initWithRootViewController:director_];
navController_.navigationBarHidden = YES;

现在您应该能够在顶部覆盖纵向视图。

希望这可以帮助!

于 2012-12-06T02:30:37.067 回答
1

在 AppDelegate.mm 中使用此代码

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0

-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}

- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
    return UIInterfaceOrientationMaskLandscape;
}
#else
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
#endif
于 2012-12-06T11:35:49.017 回答
0

在 IOs6 shouldAutorotateToInterfaceOrientation 方法不起作用,所以你在 appDelegate .m 文件 [window addSubview:viewcontroller] 更改为 [window setRootviewcontroller:viewcontroller] 后它的工作正常。

于 2012-12-06T06:26:15.363 回答