UISplitViewController の詳細ビューとして cocos2d 2 ビューを取得しました。何らかの理由で、最初と画面を回転させたときの両方で、画面全体があるかのようにビューのサイズを変更しています。ここにいくつかの構成された背景があります:

シミュレーターで実行すると、次のようになります。

関連するすべてのファイルは次のとおりです。
Game1ViewController.h
#import <UIKit/UIKit.h>
#import "cocos2d/cocos2d.h"
@class Game1Scene;
@interface Game1ViewController : UIViewController {
// Game1Scene *_scene;
}
@property (非アトミック、保持) Game1Scene *scene;
@終わり
Game1ViewController.m
#import "cocos2d/cocos2d.h"
#import "Game1Scene.h"
#import "Game1ViewController.h"
#import "CCSpriteExtensions.h"
@実装 Game1ViewController
@synthesize シーン = _scene;
- (CGRect)getRotatedBounds:(UIInterfaceOrientation)toInterfaceOrientation {
CGRect screenRect = [self.view 境界];
// NSLog(@"%f, %f\n", [UIScreen mainScreen].bounds.size.width, self.view.frame.size.height - 88);
CGRect rect = CGRectZero;
if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
rect = screenRect;
} else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
rect.size = CGSizeMake( screenRect.size.height, screenRect.size.width );
}
rect を返します。
}
- (void)startCocos2D {
CCDirector *director = [CCDirector sharedDirector];
CGSize screenSize = [[CCDirector sharedDirector] winSize];
NSLog(@"\n===========Size=%f, %f\n\n",screenSize.height, screenSize.width);
// iPhone 4 で高解像度モード (Retina ディスプレイ) を有効にし、他のすべてのデバイスで低解像度を維持します
if( ! [director enableRetinaDisplay:YES] )
CCLOG(@"Retina ディスプレイはサポートされていません");
NSLog(@"self.view 境界の幅、高さ: %f %f", [self.view 境界].size.width, [self.view 境界].size.height);
CGRectrotatedBounds = [self getRotatedBounds:[UIApplication sharedApplication].statusBarOrientation];
CCGLView *glview = [ CCGLView viewWithFrame:rotatedBounds
pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8
depthFormat:0 // GL_DEPTH_COMPONENT16_OES
];
[self.view addSubview:glview];
[ディレクター setView:glview];
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
self.scene = [Game1Scene nodeWithBounds:rotatedBounds];
CCScene *scene = [CCScene ノード];
[シーン addChild: self.scene];
[監督 runWithScene:シーン];
}
// viewDidLoad を実装して、通常は nib からビューをロードした後に追加のセットアップを行います。
- (void)viewDidLoad {
self.title = @"ゲーム 1 をプレイ";
// self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
// self.view.autoresizingMask = 1;
[super viewDidLoad];
[セルフスタートCocos2D];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// はいを返します。
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 期間:(NSTimeInterval)期間
{
CGRectrotatedBounds = [self getRotatedBounds: toInterfaceOrientation];
CCDirector *director = [CCDirector sharedDirector];
CCGLView *glView = [ディレクタ ビュー];
float contentScaleFactor = [ディレクター contentScaleFactor];
if( contentScaleFactor != 1 ) {
rotatedBounds.size.width *= contentScaleFactor;
rotatedBounds.size.height *= contentScaleFactor;
}
glView.frame =rotatedBounds;
[self.scene setBounds:rotatedBounds];
}
- (void)stopCocos2D {
CCDirector *director = [CCDirector sharedDirector];
CCGLView *view = [ディレクター ビュー];
[removeFromSuperview を表示];
//[ディレクターのデタッチ];
[ディレクターストップアニメーション];
[ディレクター一時停止];
//[ディレクター setOpenGLView:nil];
// ディレクターを殺す
[ディレクター終了];
}
- (void)viewDidDisappear:(BOOL)アニメーション {
[自己停止Cocos2D];
[super viewDidDisappear:animated];
}
@終わり
Game1Scene.h
#import <Foundation/Foundation.h>
#import "cocos2d/cocos2d.h"
@interface Game1Scene : CCLayer {
CGRect 境界_;
}
+ (id) nodeWithBounds:(CGRect)bounds;
- (void)setBounds:(CGRect)bounds;
@終わり
Game1Scene.m
#import "Game1Scene.h"
#import "CCSpriteExtensions.h"
#import "cocos2d/CCMenuItem.h"
@interface Game1Scene (プライベート)
- (void)startGame;
- (void)createUI;
- (id)initWithBounds:(CGRect)bounds;
@終わり
@実装 Game1Scene
+(id) nodeWithBounds:(CGRect)bounds {
return [[self alloc] initWithBounds:bounds];
}
- (void) setBounds:(CGRect)bounds {
NSLog(@"bounds.width, bounds.height: %f , %f", bounds.size.width, bounds.size.height);
bounds_ = 境界;
[自己 createUI];
}
-(id) initWithBounds:(CGRect)bounds {
if( (self=[スーパー初期化] )) {
srand ( 時間 (NULL) );
bounds_ = 境界;
[セルフスタートゲーム];
}
自分自身を返します。
}
- (無効) createUI {
[self removeAllChildrenWithCleanup:TRUE];
// 無地の暗い紫色の背景
CCSprite *background = [CCSprite spriteWithFile:@"game1-background.png"];
background.position = ccp(0, 0);
background.anchorPoint = ccp(0, 0);
NSLog(@"\n=== bounds= %f, %f\n", bounds_.size.width, bounds_.size.height);
[背景 resizeTo:CGSizeMake(bounds_.size.width, bounds_.size.height)];
[self addChild:background];
}
- (void)startGame {
[自己 createUI];
}
@終わり
CCSpriteExtensions.h
/*
CCSpriteExtensions.h
http://www.learn-cocos2d.com/tag/ccspriteextensions/
*/
#import "cocos2d/cocos2d.h"
@interface CCSprite (拡張機能)
// 倍率を正しく設定して、指定したサイズにサイズ変更します。
-(void)resizeTo:(CGSize) theSize;
@終わり
CCSpriteExtension.m
/*
CCSpriteExtensions.m
ソース: http://www.learn-cocos2d.com/tag/ccspriteextensions/
*/
#import "CCSpriteExtensions.h"
@implementation CCSprite (拡張機能)
-(void)resizeTo:(CGSize) theSize
{
CGFloat newWidth = theSize.width;
CGFloat newHeight = theSize.height;
float startWidth = self.contentSize.width;
float startHeight = self.contentSize.height;
float newScaleX = newWidth/startWidth;
float newScaleY = newHeight/startHeight;
self.scaleX = newScaleX;
self.scaleY = newScaleY;
}
@終わり
私はこの質問で説明されているようにアイデアを取りました: DetailViews でいくつかの Cocos2D シーンを作成することにより、ストーリーボードを備えた iPadの UISplitViewController 。
[アップデート]
2.0にアップデートしました。私の問題は次のようなものです。http://www.cocos2d-iphone.org/forum/topic/30797