1

我正在用 ios 开发一个 cocos2d 游戏。这是应用程序委托的代码:

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.homeViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.window.rootViewController = self.homeViewController;
    [self.window makeKeyAndVisible];

在这方面,我正在使ViewController课程成为rootViewController. 我正在GameOptionsViewController上课HomeViewController上课。从GameOptionsViewController我调用应用程序委托中的方法来添加游戏场景。

-(void)addGameScene

    {

    CCDirector *director = [CCDirector sharedDirector];
    if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
        [CCDirector setDirectorType:kCCDirectorTypeMainLoop];
    else {
        [CCDirector setDirectorType:kCCDirectorTypeDisplayLink];
    }

    // Init the View Controller
    viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
    viewController.wantsFullScreenLayout = YES;
    if(!glView)
        glView = [[EAGLView alloc] initWithFrame:[window bounds]];
    [director setOpenGLView:glView];

    [director setOpenGLView:glView];
    [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
    [viewController setView:glView];
    [window setRootViewController:viewController];
    [window addSubview: viewController.view];
    [window makeKeyAndVisible];
    [[CCDirector sharedDirector] runWithScene: [HelloWorldLayer scene]];
}

现在当我想隐藏游戏场景时,我使用代码:

   [[CCDirector sharedDirector] stopAnimation];
   [[CCDirector sharedDirector].openGLView setHidden:YES];

游戏场景被隐藏了,但是之前的视图,ieGameOptionsViewController没有显示出来。我做错了什么???..请指教..

4

1 回答 1

1

在这里,您像这样使用 viewController 设置 RootViewController..

[window setRootViewController:viewController];

因为它只是将您的GameOptionsViewController类对象设置为 rootViewController..

对于前。

   ViewController *homeViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
   window.rootViewController = homeViewController;

我希望这可以帮助你...

于 2012-12-05T09:23:32.913 回答