1

We've been having trouble with this issue for a while, and just cannot find the answer to it in the docs or online searches..

Our iOS game is based on OpenGL ES, and we are implementing GameCenter turn based gaming. The following code shows a matchmaking UI for creating a turn based match. This code works fine on my iPad 1 and iPad 3. However, it will not work on my 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 / ストーリーボードを使用する代わりに、ビュー階層全体をコードで初期化する必要があります。

以前の初期化手順は次のとおりです。

  1. UIWindow の初期化とキーの作成。
  2. UIWindow addView (OpenGL ウィンドウ)。
  3. UIWindow addView (タッチ レスポンダー UIView)。
  4. UIWindow rootViewController = [[ViewController alloc] init];

ビューを UIWindow に直接追加すると、View Controller の機能が妨げられ、iPhone と iPad で未定義の動作が発生します。

新しい初期化手順 (これらの問題を抱えている人がいる場合にこれらの問題を修正するため):

  1. UIWindow の初期化とキーの作成。
  2. UIWindow rootViewController = [[ViewController alloc] init];
  3. rootViewController.view = [[GLAndTouchView alloc] init];

うまくいけば、同じ問題に悩まされている人なら誰でもこれが役に立つと思うでしょう。

于 2012-11-27T15:48:36.443 に答える