1

我有一部 iPhone 4S(运行 iOS 5.1)和一部 iPhone 5(运行 iOS 6.1)。我注意到当我尝试打开cocos2D游戏时,在运行 5.1 的 iPhone 4S 上,游戏能够以横向模式完美打开。

但是,当我尝试在cocos2D运行 6.1 的 iPhone 5 上打开相同的游戏时,游戏以纵向模式打开。

有什么方法可以cocos2D在运行 iOS 6.1 的 iPhone 5 中将游戏旋转到横向模式。

一些额外的说明:

  • 游戏是从我的测试应用程序中的视图控制器推送的。
  • 由于我是从 iOS 应用程序推送游戏,因此我必须在“支持界面方向”部分支持纵向模式。(如果我只是在玩游戏,我会轻松地将支持界面方向设置为横向左/横向右)

我还尝试了不同的方法,例如 iOS 6,例如:

-(NSUInteger)supportedInterfaceOrientations
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
-(BOOL)shouldAutorotate

但是当我尝试这些方法时,它给了我不同的结果。

理想情况下,我希望将应用程序锁定为纵向模式,并将游戏锁定为横向模式。

所以,我想知道是否有可能有一个应用程序在打开时保持锁定在纵向模式和游戏锁定在横向模式(适用于 iOS 5 和 iOS 6)?

这是我正在处理的示例项目的链接:

http://www.4shared.com/zip/yEAA1D_N/MyNinjaGame.html

4

2 回答 2

2

我只是将 Xcode 中的方向模式(目标上的“摘要”选项卡)设置为左右横向。然后对于每个 UIViewController 我添加了这个:

// Autorotation iOS5 + iOS6
- (BOOL)shouldAutorotateToInterfaceOrientation:    (UIInterfaceOrientation)toInterfaceOrientation {
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
于 2013-06-04T13:34:39.727 回答
1

我在 cocos2d 游戏(在 iOS 6.1 上)中为景观做的事情:

//This is in the AppDelegate.m
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
//change to 'return UIInterfaceOrientationIsPortrait(interfaceOrientation);' for portrait
}
于 2013-05-06T17:54:17.680 回答