1

这个问题我们已经有一段时间了,只是在文档或在线搜索中找不到答案。

我们的 iOS 游戏基于 OpenGL ES,我们正在实现 GameCenter 回合制游戏。以下代码显示了用于创建基于回合的匹配的匹配 UI。此代码在我的 iPad 1 和 iPad 3 上运行良好。但是,它不适用于我的 iPhone 4S!

[更新:]我们在视图层次结构的顶部使用 UIWindow,将 GL 视图/层作为子视图。当它被呈现时,这掩盖了新的观点。我现在可以通过在主窗口中添加一个 UIView 来看到这个窗口,并将 GL 视图作为它的子视图。但是,我仍然无法与此视图交互..

此代码来自我们混合 C++ 和 Objective-C 代码的 .mm 文件。

// Configure the match making view, with our own delegate
GKTurnBasedMatchmakerViewController *mmvc = 
[[GKTurnBasedMatchmakerViewController alloc] 
 initWithMatchRequest:request];    
mmvc.showExistingMatches = YES;


// Uses our own delegate.
if(!g_pTurnBasedDelegate)
{
    g_pTurnBasedDelegate = [[TurnBasedDelegate alloc] init];
}

mmvc.turnBasedMatchmakerDelegate = g_pTurnBasedDelegate;

// Get the main window's root controller and instruct it to show the match making delegate.
if(g_Env && g_Env->m_pWindow)
{
    RefPtr<WindowIOS> pIOSWin = ref_static_cast<WindowIOS>(g_Env->m_pWindow);

    UIWindow * pUIWin = (UIWindow *)pIOSWin->GetHandle();
    UIViewController * pController = [pUIWin rootViewController];


    if(pController)
    {
        g_pRootViewController = pController;
    }

}

if(g_pRootViewController)
{
    [g_pRootViewController presentViewController:mmvc animated:YES completion:nil];
}
4

1 回答 1

2

一段时间后回到这个问题。问题不在于 Game Center 控制器,而在于我们如何设置主应用程序视图。这恰好适用于 iPad,但不适用于 iPhone。

对于我们的应用程序,我们需要在代码中初始化整个视图层次结构,而不是使用 NIB / Storyboard。

我们旧的初始化步骤是:

  1. UIWindow 初始化并生成密钥。
  2. UIWindow addView(我们的 OpenGL 窗口)。
  3. UIWindow addView(一个触摸响应 UIView)。
  4. UIWindow rootViewController = [[ViewController alloc] init];

将我们的视图直接添加到 UIWindow 会阻碍视图控制器的功能,并导致 iPhone 与 iPad 上的未定义行为。

我们新的初始化步骤(如果有人遇到这些问题,可以解决这些问题):

  1. UIWindow 初始化并生成密钥。
  2. UIWindow rootViewController = [[ViewController alloc] init];
  3. rootViewController.view = [[GLAndTouchView alloc] init];

希望任何遇到同样问题的人都会发现这很有用。

于 2012-11-27T15:48:36.443 回答