title: UIWindow with wrong size when using landscape orientation
body: <p>I have an empty application and there is no storyboard or xib involved. I want to have a hidden status bar and support only landscape orientation. Again, I wan't to make those changes only within code and don't touch the Info.plist.</p>
  
  <h1>Problem</h1>
  
  <p>I create a UIWindow with a controller that says the only supported orientation is landscape. In that case my UIWindow is created in the dimension of portrait mode and doesn't rotate. The expected result would be a screen that is completely cyan.</p>
  
  <p><img src="https://i.stack.imgur.com/GwDA9.png" alt="Broken UIWindow"></p>
  
  <p>This is my delegate:</p>
  
  <pre><code>#import "AppDelegate.h"
  #import "AppViewController.h"
  
  @implementation AppDelegate
  
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor cyanColor];
    self.window.rootViewController = [[AppViewController alloc] init];
    [self.window makeKeyAndVisible];
    return YES;
  }
  
  @end
  </code></pre>
  
  <p>This is my controller:</p>
  
  <pre><code>#import "AppViewController.h"
  
  @implementation AppViewController
  
  - (BOOL)shouldAutorotate {
    return YES;
  }
  
  - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeLeft;
  }
  
  - (BOOL)prefersStatusBarHidden {
    return YES;
  }
  
  - (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
  }
  
  @end
  </code></pre>
  
  <h1>What I've tried so far</h1>
  
  <p>If I set the rootViewController after calling makeKeyAndVisible everything seems to work at first.</p>
  
  <pre><code>self.window.backgroundColor = [UIColor cyanColor];
  [self.window makeKeyAndVisible];
  self.window.rootViewController = [[AppViewController alloc] init];
  </code></pre>
  
  <p>There are still some issues. First of all I don't like this since it seems to be very fragile. Second problem is that in a more complex application that sets a GLKViewController as the rootViewController I get the following result (expected would be no black area on the left):</p>
  
  <p><img src="https://i.stack.imgur.com/yHXPC.png" alt="Broken GLKViewController"></p>
  
  <p>It looks like the status bar is not hidden early enough. Several gesture recognizers are active and in the GLKViewController and clicking on the black area yields the following log message:</p>
  
  <blockquote>
    <p>2014-09-25 13:20:42.170 StackOverflowExample[6971:107907] unexpected nil window in
    _UIApplicationHandleEventFromQueueEvent, _windowServerHitTestWindow: UIClassicWindow: 0x7fa20b805e00; frame = (0 0; 375 667);
    userInteractionEnabled = NO; gestureRecognizers = NSArray:
    0x7fa20b80a620; layer = UIWindowLayer: 0x7fa20b806890</p>
  </blockquote>
  
  <p>I also performed various other changes, like attaching an empty UIViewController and adding my view as a sub-view. In that case my view looks correct but the window is still using the wrong dimensions.</p>
  
  <p>Everything rotates correct if I do not override the supportedInterfaceOrientations methods in my view controller. But that is of course not what I want.</p>