title: Cocos2d View not sizing properly in UISplitViewController
body: <p>I've got a cocos2d 2 view as the Detail View in a <code>UISplitViewController</code>.  For some reason, it's sizing the view as if it had the entire screen, both initially and when I rotate the screen. Here's some made up background:</p>
  <p><img src="https://i.stack.imgur.com/WdM3B.png" alt="background" /></p>
  <p>Here's what it looks like when I run it in the simulator:</p>
  <p><img src="https://i.stack.imgur.com/xo4nn.png" alt="simulator" /></p>
  <p>Here are all the relevant files:</p>
  <p><b>Game1ViewController.h</b></p>
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import &quot;cocos2d/cocos2d.h&quot;
  
  @class Game1Scene;
  
  @interface Game1ViewController : UIViewController {
      //  Game1Scene *_scene;
  }
  
  @property (nonatomic, retain) Game1Scene *scene;
  
  @end
  </code></pre>
  <p><b>Game1ViewController.m</b></p>
  <pre><code>
  #import &quot;cocos2d/cocos2d.h&quot;
  #import &quot;Game1Scene.h&quot;
  #import &quot;Game1ViewController.h&quot;
  #import &quot;CCSpriteExtensions.h&quot;
  
  @implementation Game1ViewController
  @synthesize scene = _scene;
  
  - (CGRect)getRotatedBounds:(UIInterfaceOrientation)toInterfaceOrientation  {
      CGRect screenRect = [self.view bounds];
  //    NSLog(@&quot;%f, %f\n&quot;, [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 );
      }
      return rect;
  }
  
  - (void)startCocos2D {
      
      CCDirector *director = [CCDirector sharedDirector];
      CGSize screenSize = [[CCDirector sharedDirector] winSize];
      NSLog(@&quot;\n===========Size=%f, %f\n\n&quot;,screenSize.height, screenSize.width);
      
      // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
      if( ! [director enableRetinaDisplay:YES] )
          CCLOG(@&quot;Retina Display Not supported&quot;);
          
      NSLog(@&quot;self.view bounds width, height: %f %f&quot;, [self.view bounds].size.width, [self.view bounds].size.height);
      
      CGRect rotatedBounds = [self getRotatedBounds:[UIApplication sharedApplication].statusBarOrientation];
      
      CCGLView *glview  = [ CCGLView  viewWithFrame:rotatedBounds
                                      pixelFormat:kEAGLColorFormatRGB565  // kEAGLColorFormatRGBA8
                                      depthFormat:0                       // GL_DEPTH_COMPONENT16_OES
                          ];
          
      [self.view addSubview:glview];
          
      [director setView:glview];
      
      [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
      
      self.scene = [Game1Scene nodeWithBounds:rotatedBounds];
      CCScene *scene = [CCScene node];
      [scene addChild: self.scene];
      [director runWithScene: scene];
      
  }
  
  // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  - (void)viewDidLoad {
      self.title = @&quot;Play Game1&quot;;
  //    self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  //    self.view.autoresizingMask = 1;
      [super viewDidLoad];
      
      [self startCocos2D];
  }
  
  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
      return (interfaceOrientation == UIInterfaceOrientationPortrait);
  }
  
  - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
  {
      CGRect rotatedBounds = [self getRotatedBounds: toInterfaceOrientation];
      
      CCDirector *director = [CCDirector sharedDirector];
      CCGLView *glView = [director view];
      float contentScaleFactor = [director 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 = [director view];
      [view removeFromSuperview];
      //[director detach];
      
      [director stopAnimation];
      [director pause];
      //[director setOpenGLView:nil];
      
      // kill the director
      [director end];
  }
  
  - (void)viewDidDisappear:(BOOL)animated {
      [self stopCocos2D];
      [super viewDidDisappear:animated];
  }
  @end
  
  </code></pre>
  <p><b>Game1Scene.h</b></p>
  <pre><code>#import &amp;lt;Foundation/Foundation.h&gt;
  #import &quot;cocos2d/cocos2d.h&quot;
  
  @interface Game1Scene : CCLayer {
      CGRect bounds_;
  }
  
  + (id) nodeWithBounds:(CGRect)bounds;
  - (void)setBounds:(CGRect)bounds;
  @end
  </code></pre>
  <p><b>Game1Scene.m</b></p>
  <pre><code>#import &quot;Game1Scene.h&quot;
  #import &quot;CCSpriteExtensions.h&quot;
  #import &quot;cocos2d/CCMenuItem.h&quot;
  
  @interface Game1Scene (Private)
  
  - (void)startGame;
  - (void)createUI;
  - (id)initWithBounds:(CGRect)bounds;
  
  @end
  
  @implementation Game1Scene
  
  +(id) nodeWithBounds:(CGRect)bounds {
      return  [[self alloc] initWithBounds:bounds];
  }
  
  - (void) setBounds:(CGRect)bounds {
      NSLog(@&quot;bounds.width, bounds.height: %f , %f&quot;, bounds.size.width, bounds.size.height);
      bounds_ = bounds;
      [self createUI];
  }
  
  - (id) initWithBounds:(CGRect)bounds {
      if( (self=[super init] )) {
          srand ( time(NULL) );
          
          bounds_ = bounds;
          
          [self startGame];
      }
      return self;
  }
  
  - (void) createUI {
      
      [self removeAllChildrenWithCleanup:TRUE];
      
      // Plain dark purple background
      CCSprite *background = [CCSprite spriteWithFile:@&quot;game1-background.png&quot;];
      background.position = ccp(0, 0);
      background.anchorPoint = ccp(0, 0);
      NSLog(@&quot;\n=== bounds= %f, %f\n&quot;, bounds_.size.width, bounds_.size.height);
      [background resizeTo:CGSizeMake(bounds_.size.width, bounds_.size.height)];
      [self addChild:background];
      
  }
  
  - (void)startGame {
      [self createUI];
  }
  
  @end
  </code></pre>
  <p><b>CCSpriteExtensions.h</b></p>
  <pre><code>/*
   CCSpriteExtensions.h
  
   http://www.learn-cocos2d.com/tag/ccspriteextensions/
   */
  #import &quot;cocos2d/cocos2d.h&quot;
  
  @interface CCSprite (Xtensions)
  
  // Resize to the specified size by setting the scale factors correctly.
  - (void)resizeTo:(CGSize) theSize;
  
  @end
  </code></pre>
  <p><b>CCSpriteExtension.m</b></p>
  <pre><code>/*
   CCSpriteExtensions.m
   
   Source: http://www.learn-cocos2d.com/tag/ccspriteextensions/
   */
  #import &quot;CCSpriteExtensions.h&quot;
  
  @implementation CCSprite (Xtensions)
  
  - (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;
      
  }
  @end
  </code></pre>
  <p>I took the idea as explained in this question: <a href="https://stackoverflow.com/questions/9272244/uisplitviewcontroller-on-ipad-with-storyboards">UISplitViewController on iPad with Storyboards</a> by creating a couple of Cocos2D Scenes in the DetailViews.</p>
  <h2>Update</h2>
  <p>I updated to 2.0.  My problem sounds like something similar to this: <a href="http://www.cocos2d-iphone.org/forum/topic/30797" rel="nofollow noreferrer">http://www.cocos2d-iphone.org/forum/topic/30797</a></p>