0

我在 iOS 应用程序中有一个普通的故事板。它包含带有按钮的 ViewController "A"。当该按钮被点击时,它会加载一个 Cocos2D 视图 - 为此,我只需从创建新 Cocos2D 项目时获得的默认 AppDelegate 复制代码:

window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];


CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
                               pixelFormat:kEAGLColorFormatRGB565   
                               depthFormat:0    
                        preserveBackbuffer:NO
                                sharegroup:nil
                             multiSampling:NO
                           numberOfSamples:0];

[glView setMultipleTouchEnabled:YES];

director_ = (CCDirectorIOS*) [CCDirector sharedDirector];

director_.wantsFullScreenLayout = YES;

[director_ setDisplayStats:YES];


[director_ setAnimationInterval:1.0/60];

[director_ setView:glView];

[director_ setDelegate:self];

[director_ setProjection:kCCDirectorProjection2D];

if( ! [director_ enableRetinaDisplay:YES] )
    CCLOG(@"Retina Display Not supported");

[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];

CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
[sharedFileUtils setEnableFallbackSuffixes:NO];             // Default: NO. No fallback suffixes are going to be used
[sharedFileUtils setiPhoneRetinaDisplaySuffix:@"-hd"];      // Default on iPhone RetinaDisplay is "-hd"
[sharedFileUtils setiPadSuffix:@"-ipad"];                   // Default on iPad is "ipad"
[sharedFileUtils setiPadRetinaDisplaySuffix:@"-ipadhd"];    // Default on iPad RetinaDisplay is "-ipadhd"


[CCTexture2D PVRImagesHavePremultipliedAlpha:YES];


[director_ pushScene: [HelloWorldLayer scene]];


navController_ = [[UINavigationController alloc] initWithRootViewController:director_];
navController_.navigationBarHidden = YES;

[window_ setRootViewController:navController_];


[window_ makeKeyAndVisible];

这一切都很好,加载“HelloWorldLayer”时它就像一个魅力。但是,我似乎无法删除此“HelloWorldLayer”并使应用程序重新使用情节提要。目前,我的“HelloWorldLayer”中有一个函数,它执行以下操作:

[[CCDirector sharedDirector].openGLView removeFromSuperview];
[[CCDirector sharedDirector] removeFromParentViewController];
[self removeFromParentAndCleanup:TRUE];

这在从项目中删除 Cocos2D 时效果很好,但是在完成上述操作后,我无法点击 ViewController“A”中的任何内容:按钮不响应触摸 - 就好像应用程序已冻结一样。

帮助将不胜感激!

PS:这是一个有问题的文件的链接:http ://www.mediafire.com/?ipnlpinl5i0lw4a

4

1 回答 1

0

好的,我想通了:window_在第一行代码中分配的仍然覆盖 ViewController A。[window_ release]一旦 HelloWorldLayer 视觉上消失,我必须从 ViewController A 调用以将其移开。

于 2013-01-12T23:35:53.207 回答