游戏中心 - 方向

时间:2010-10-29 15:25:36

标签: ios cocos2d-iphone game-center

Cocos2d版本:v0.99.04

我正在将Game Center添加到我当前的应用程序中,我找到了一些代码来打开GKMatchmakerViewController。它似乎工作得很好,除非它被解雇,它将模拟器中的方向更改为肖像。游戏只在景观中运行。我将设备旋转回横向并且所有cocos2d场景仍然可以正常工作,但如果我打开警报或同伴选择器,它们将以纵向模式打开。我可以打开和关闭场景,但现在他们都会显示这种行为。这也是使用实际设备发生的。

// *.h
UIViewController *tempVC;

// *.m

// Open

GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = 2;
request.maxPlayers = 2;

GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];
mmvc.matchmakerDelegate = self;

tempVC=[[UIViewController alloc] init];
[[[CCDirector sharedDirector] openGLView] addSubview:tempVC.view];
[tempVC presentModalViewController: mmvc animated: YES];    

// Close

[tempVC dismissModalViewControllerAnimated:YES];
[tempVC.view removeFromSuperview];
[tempVC release];

一旦我点击dismissModalViewControllerAnimated,那就是模拟器旋转的时候。

提前感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

我有同样的问题(不使用cocos2d),我通过继承游戏中心附加的UIViewController来解决它:

@interface GameCenterViewController : UIViewController
{
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;

@end


@implementation GameCenterViewController

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    // Does it match my screenOrientation?
        if (sceneOrientation == (UIDeviceOrientation)toInterfaceOrientation)
        return YES;

    return NO;
}

@end

答案 1 :(得分:0)

AppDelegate.m

之前将其放入@implementation
@interface UINavigationController (Private)

- (NSUInteger)supportedInterfaceOrientations;
- (BOOL)shouldAutorotate;

@end

@implementation UINavigationController (Private)

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL)shouldAutorotate
{
    return YES;
}

@end