4

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,那就是模拟器旋转的时候。

提前感谢您的帮助。

4

2 回答 2

0

AppDelegate.m先放这个@implementation

@interface UINavigationController (Private)

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

@end

@implementation UINavigationController (Private)

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL)shouldAutorotate
{
    return YES;
}

@end
于 2013-03-02T15:38:43.727 回答
0

我遇到了同样的问题(不使用 cocos2d),我通过继承 Game Center 所连接的 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
于 2011-09-04T19:39:25.753 回答