<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

      Add UIViewController in cocos2d(在 cocos2d 中添加 UIViewController)
      • <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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
                Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
                Resume game cocos2d(恢复游戏 cocos2d)
                Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
                Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
                Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)
                • <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>
                      <tbody id='DFpyr'></tbody>

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

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