【问题标题】:Game Center - orientation游戏中心 - 方向
【发布时间】:2010-10-29 15:25:35
【问题描述】:

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,模拟器就会旋转。

提前感谢您的帮助。

【问题讨论】:

    标签: ios cocos2d-iphone game-center


    【解决方案1】:

    我遇到了同样的问题(不使用 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
    

    【讨论】:

      【解决方案2】:

      把这个放在AppDelegate.m@implementation之前

      @interface UINavigationController (Private)
      
      - (NSUInteger)supportedInterfaceOrientations;
      - (BOOL)shouldAutorotate;
      
      @end
      
      @implementation UINavigationController (Private)
      
      - (NSUInteger)supportedInterfaceOrientations
      {
          return UIInterfaceOrientationMaskLandscape;
      }
      
      - (BOOL)shouldAutorotate
      {
          return YES;
      }
      
      @end
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多