我在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
答案 0 :(得分:0)
好的,我明白了:在第一行代码中分配的window_
仍然覆盖了ViewController A.一旦HelloWorldLayer在视觉上消失,我必须从ViewController A调用[window_ release]
把它弄开。