如何在iOS 6中将cocos2D游戏旋转到横向模式?

时间:2013-05-06 15:56:06

标签: iphone objective-c ios5 ios6 cocos2d-iphone

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

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

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

一些额外的说明:

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

我也尝试过不同的方法,例如iOS 6,例如:

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

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

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

所以,我想知道是否可以让一个应用程序在纵向模式下保持锁定状态,并且游戏在横向模式下锁定(适用于iOS 5和iOS 6)?

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

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

2 个答案:

答案 0 :(得分:2)

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

// Autorotation iOS5 + iOS6
- (BOOL)shouldAutorotateToInterfaceOrientation:    (UIInterfaceOrientation)toInterfaceOrientation {
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}

答案 1 :(得分: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
}
相关问题