在解雇游戏中心后,应用程序停止响应触摸

时间:2012-09-22 07:11:52

标签: ios game-center

在解除任何Gamecenter叠加层后,叠加层会正确消失,我的游戏窗口会再次显示,但它不响应触摸。 我已经搜索谷歌的答案,并提出了很多建议,但没有任何效果。这是我目前的代码:

 GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
    if (gameCenterController != nil)
    {
       window = [[UIApplication sharedApplication] keyWindow];
       gameView = [[window subviews] objectAtIndex:0];

       gameCenterController.gameCenterDelegate = self;
       gameCenterController.viewState = GKGameCenterViewControllerStateAchievements;
       tempVC=[[UIViewController alloc] init];

       [[UIApplication sharedApplication].keyWindow addSubview:tempVC.view];
       [tempVC presentViewController: gameCenterController animated: YES completion:nil];
    }



 - (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController
 {
     [tempVC dismissViewControllerAnimated:YES completion:nil];
     [tempVC.view removeFromSuperview];
     [tempVC release];


     [window becomeFirstResponder];
     [window bringSubviewToFront:gameView];
     [window makeKeyAndVisible];
 }

1 个答案:

答案 0 :(得分:2)

您需要释放游戏中心视图控制器,并在完成解雇动画后使主窗口成为第一响应者。这是正确的代码:

- (void)gameCenterViewControllerDidFinish:
(GKGameCenterViewController *)gameCenterViewController {

    [tempVC dismissViewControllerAnimated:YES completion: ^(void) {
        [tempVC.view removeFromSuperview];
        [tempVC release];

        [window becomeFirstResponder];
        [window bringSubviewToFront:gameView.view];
        [window makeKeyAndVisible];
     } ];
}