Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 新的视图控制器出现,然后消失在场景后面_Ios_Uiviewcontroller_Cocos2d Iphone - Fatal编程技术网

Ios 新的视图控制器出现,然后消失在场景后面

Ios 新的视图控制器出现,然后消失在场景后面,ios,uiviewcontroller,cocos2d-iphone,Ios,Uiviewcontroller,Cocos2d Iphone,我正在使用将代码集成到我的cocos2d 0.99.5项目中。我在正确加载视图控制器时遇到一些困难。我以前从未将coco2d与标准的Cocoa-Touch用户界面混合使用过,我有点不知所措 当连接到Twitter时,我在我的应用程序委托中调用以下代码: -(void) twitterAccountLogin { UIViewController *controller = nil; if (!_engine) { _engine = [[SA_OAuthTwitt

我正在使用将代码集成到我的cocos2d 0.99.5项目中。我在正确加载视图控制器时遇到一些困难。我以前从未将coco2d与标准的Cocoa-Touch用户界面混合使用过,我有点不知所措

当连接到Twitter时,我在我的应用程序委托中调用以下代码:

-(void) twitterAccountLogin
{
    UIViewController *controller = nil;
    if (!_engine) {
        _engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate: self];
        _engine.consumerKey = kOAuthConsumerKey;
        _engine.consumerSecret = kOAuthConsumerSecret;

        controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine: _engine delegate: self];
    }

    if (controller) {
        [[CCDirector sharedDirector] stopAnimation];
        [viewController presentModalViewController:controller animated:YES];
        [controller release];
        return;
    }
} 
调用此函数时,会创建Twitter
UIViewController
,它会在屏幕上设置动画,然后,一旦完成动画设置(即,它到达屏幕顶部),它就会消失。当前运行的
CCScene
会重新出现,但不会对触摸做出响应。在模拟器上,屏幕将变黑,而不是重新显示运行场景。如果不清楚,
viewController
是最近在0.99.5中添加到cocos2d的
RootViewController


在我看来,
UIViewController
正在创建中,然后以某种方式在运行场景下绘制,但调试却毫无进展。我哪里出错了?

您的视图控制器应该是这样的:

[[[CCDirector sharedDirector]openGLView] addSubview: viewController.view]; 
[viewController presentModalViewController: controller animated:YES];

在这里和cocos2d论坛上搜索帮助后,以下是我最终所做的

-(void)pauseMenuButtonPressed
{    
    if(!paused)
    {
        paused = TRUE;

        [[CCDirector sharedDirector] pause];

        CGSize s = [[CCDirector sharedDirector] winSize];
        pauseLayer = [CCColorLayer layerWithColor: ccc4(150, 150, 150, 125) width: s.width height: s.height];
        pauseLayer.position = CGPointZero;
        [self addChild: pauseLayer z:8];

        CCMenuItem *pauseMenuItemResume =[CCMenuItemImage itemFromNormalImage:@"menuItemResumeSmall.png"
                                                            selectedImage: @"menuItemResumeSmallSelected.png"
                                                                   target:self
                                                                 selector:@selector(pauseMenuResumeSelected)];


        CCMenuItem *pauseMenuItemMainMenu =[CCMenuItemImage itemFromNormalImage:@"menuItemMainMenuSmall.png"
                                                              selectedImage: @"menuItemMainMenuSmallSelected.png"
                                                                     target:self
                                                                   selector:@selector(pauseMenuExitToMainMenuSelected)];

        // Create the pause menu and add the menu items to it
        pauseMenu = [CCMenu menuWithItems:pauseMenuItemResume, pauseMenuItemMainMenu, nil];

        // Arrange the menu items vertically
        [pauseMenu alignItemsVertically];

        // add the menu to the scene
        [self addChild:pauseMenu z:10];

        [hudButtons setIsTouchEnabled:NO];
    }

}

简言之,我暂停游戏中的所有动作,创建一个覆盖屏幕的透明层,然后在上面显示菜单,而不是推一个新场景来创建暂停菜单。这似乎是cocos2d中处理此问题的常规方法,至少从0.99.5开始(这就是游戏当前运行的内容)。

我应该澄清viewController是项目的RootViewController——将其视图作为子视图添加到CCDirector会创建一个无限循环,导致应用程序崩溃。该问题现已编辑澄清。不过,我很感谢你的帮助!如果将viewController声明为:viewController=[[UIViewController alloc]initWithNibName:nil bundle:nil];我想会有用的。。