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