<legend id='bKp98'><style id='bKp98'><dir id='bKp98'><q id='bKp98'></q></dir></style></legend>
  1. <i id='bKp98'><tr id='bKp98'><dt id='bKp98'><q id='bKp98'><span id='bKp98'><b id='bKp98'><form id='bKp98'><ins id='bKp98'></ins><ul id='bKp98'></ul><sub id='bKp98'></sub></form><legend id='bKp98'></legend><bdo id='bKp98'><pre id='bKp98'><center id='bKp98'></center></pre></bdo></b><th id='bKp98'></th></span></q></dt></tr></i><div id='bKp98'><tfoot id='bKp98'></tfoot><dl id='bKp98'><fieldset id='bKp98'></fieldset></dl></div>
    1. <tfoot id='bKp98'></tfoot>

      <small id='bKp98'></small><noframes id='bKp98'>

      • <bdo id='bKp98'></bdo><ul id='bKp98'></ul>

    2. 在 cocos2d 中添加 UIViewController

      时间:2024-08-12
      • <bdo id='0kGMX'></bdo><ul id='0kGMX'></ul>

          • <tfoot id='0kGMX'></tfoot>

            • <legend id='0kGMX'><style id='0kGMX'><dir id='0kGMX'><q id='0kGMX'></q></dir></style></legend>
                <tbody id='0kGMX'></tbody>

                <i id='0kGMX'><tr id='0kGMX'><dt id='0kGMX'><q id='0kGMX'><span id='0kGMX'><b id='0kGMX'><form id='0kGMX'><ins id='0kGMX'></ins><ul id='0kGMX'></ul><sub id='0kGMX'></sub></form><legend id='0kGMX'></legend><bdo id='0kGMX'><pre id='0kGMX'><center id='0kGMX'></center></pre></bdo></b><th id='0kGMX'></th></span></q></dt></tr></i><div id='0kGMX'><tfoot id='0kGMX'></tfoot><dl id='0kGMX'><fieldset id='0kGMX'></fieldset></dl></div>

                <small id='0kGMX'></small><noframes id='0kGMX'>

                本文介绍了在 cocos2d 中添加 UIViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想在 cocos2d 项目中显示 UIViewController,所以我在我的 CCLayer 类中这样做了:

                i want to display a UIViewController in a cocos2d project, so i have do this in my CCLayer class:

                -(void)displayMainMenu {
                    CGSize screenSize = [CCDirector sharedDirector].winSize;
                    [CCMenuItemFont setFontName:@"Marker Felt"];
                    [CCMenuItemFont setFontSize:26];
                
                    CCMenuItemFont *openViewC = [CCMenuItemFont itemWithString:@"Open View" target:self selector:@selector(loadMyViewController)];
                    mainMenu = [CCMenu menuWithItems:openViewC, nil];
                    [self addChild:mainMenu z:0];
                }
                
                -(void) loadMyViewController{
                
                    //Add the tableview when the transition is done
                    myView = [[MyViewController alloc] init];
                    UIView *viewHost = hostView.view;
                
                    [[[CCDirector sharedDirector] view] addSubview:viewHost];
                }
                

                然后在我的 ViewController 中返回我的 CCLayer 我这样做:

                and then in my ViewController to return to my CCLayer i do this:

                - (IBAction)exitAction:(id)sender
                    {
                    [self.view removeFromSuperview];
                
                    [[CCDirector sharedDirector] pushScene: [MainMenu scene]]; //i need it or not?
                }
                

                一切正常,我使用 cocos2d v2.0,但我想知道是否有更好的方法可以在 cocos2d 场景中添加 UIViewController,谢谢!

                and all work, i use cocos2d v2.0, but i want know if there is a better way to add a UIViewController in a cocos2d scene, thanks!

                推荐答案

                由于cocos2d 2.0中的director是UIViewController的子类,作为加载在AppDelegate中的导航控制器的根,其实有一个非常简单的方法可以利用UIKit 动画,如果你喜欢的话.它还使场景完好无损,而无需真正担心内存管理.您可以将您的 -loadMyViewController 方法更改为:

                Since the director in cocos2d 2.0 is a subclass of UIViewController as the root of a navigation controller loaded in the AppDelegate, there is actually a very simple way that can utilize UIKit animations, if you prefer that. It also leaves the scene intact without really worrying about memory management. You could alter your -loadMyViewController method to this:

                - (void)loadMyViewController {
                     myView = [[MyViewController alloc] init];
                     AppController *app = (AppController *)[[UIApplication sharedApplication] delegate];
                     [app.navController pushViewController:myView animated:YES];
                     [CCDirector sharedDirector].pause;
                }
                

                然后在想要返回 cocos2d 场景时简单地恢复 director 并调用 [app.navController popViewController...].或者,您可以在推送视图控制器而不是暂停时使用 stopAnimation 方法,类似于 cocos2d 处理应用进入后台的方式.

                And then simply resume the director and call [app.navController popViewController...] when you want to return to the cocos2d scene. Alternatively, you could use the stopAnimation method when you push your view controller instead of pause, similar to how cocos2d handles the app entering the background.

                这篇关于在 cocos2d 中添加 UIViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:使用 CCTouchDispatcher Cocos2d 2.0 Beta-2 ARC 下一篇:cocos2d 使用 CCSpeed 动态改变动画速度

                相关文章

              1. <i id='DFpyr'><tr id='DFpyr'><dt id='DFpyr'><q id='DFpyr'><span id='DFpyr'><b id='DFpyr'><form id='DFpyr'><ins id='DFpyr'></ins><ul id='DFpyr'></ul><sub id='DFpyr'></sub></form><legend id='DFpyr'></legend><bdo id='DFpyr'><pre id='DFpyr'><center id='DFpyr'></center></pre></bdo></b><th id='DFpyr'></th></span></q></dt></tr></i><div id='DFpyr'><tfoot id='DFpyr'></tfoot><dl id='DFpyr'><fieldset id='DFpyr'></fieldset></dl></div>

                  <tfoot id='DFpyr'></tfoot><legend id='DFpyr'><style id='DFpyr'><dir id='DFpyr'><q id='DFpyr'></q></dir></style></legend>

                    <small id='DFpyr'></small><noframes id='DFpyr'>

                      <bdo id='DFpyr'></bdo><ul id='DFpyr'></ul>