title: Rotation and multiple windows
body: <p>I'm creating a video player that manages full screen mode trying to emulate the <code>MPMoviePlayerController</code> behavior. In fact when you press the full screen button, the player view is moved to another <code>UIWindow</code> instance.<br>
  Right after the button is pressed the code generates a window with a <code>rootViewController</code> that host the player view.<br>
  The app can manage only the portrait orientation, but the view controller that hosts the player on the new window only landscape.<br>
  Everything works fine: if I press full screen the simulator rotates to landscape displaying the player in full screen.<br>
  The problem arise when I want the app to return in normal visualization, the window disappear and it returns to the "app" the problem is that the status bar remains in landscape.<bR>
  On iOS8 nothing works but that is another story.<bR>
  The app view controllers are set to support only portrait:</p>
  
  <pre><code>- (BOOL)shouldAutorotate
  {
      return YES;
  }
  
  
  - (NSUInteger)supportedInterfaceOrientations
  {
      NSUInteger orietationMask = 0;
      if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
          orietationMask = (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight);
      }
      else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
          orietationMask = (UIInterfaceOrientationMaskPortrait);
      }
      return orietationMask;
  }
  </code></pre>
  
  <p>Only the view controller that will host the player view in another window is set to support only landscape.</p>
  
  <pre><code>- (BOOL)shouldAutorotate
  {
      return YES;
  }
  
  - (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
      return UIInterfaceOrientationLandscapeLeft;
  }
  
  - (NSUInteger)supportedInterfaceOrientations
  {
      NSUInteger orietationMask = 0;
      if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
          orietationMask = (UIInterfaceOrientationMaskLandscape);
      }
      else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
          orietationMask = (UIInterfaceOrientationMaskLandscape )  ;
  
      }
      return orietationMask;
  }
  </code></pre>
  
  <p>Here a short brief about methods I use to create the window and swap views:</p>
  
  <pre><code>- (void) createWindow {
      self.playerWindow = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]] ;
      self.playerWindow.windowLevel = UIWindowLevelNormal;
      self.fullScreenViewController = [[FullScreenPlayerViewController alloc] init];
      self.playerWindow.rootViewController = self.fullScreenViewController;
  }
  
  - (void) swapPlayerViewHost {
      self.oldHostingView = self.playerView.superview;
      UIView * playerView = self.playerView;
      [playerView removeFromSuperview];
      [self.fullScreenViewController.view addSubview:playerView];
      playerView.frame = self.fullScreenViewController.bounds;
  
  }
  - (void) restorePlayerViewPosition {
      UIView * playerView = self.playerView;
      [playerView removeFromSuperview];
      [self.oldHostingView addSubview:playerView];
      playerView.frame = self.oldHostingView.bounds;
      [self.oldWindow makeKeyAndVisible];
      self.playerWindow.hidden = YES;
      self.oldHostingView = nil;
      self.playerWindow = nil;
  }
  
  #pragma mark -
  #pragma mark Movie controller methods
  
  
  - (void) setFullScreen:(BOOL) fullScreen {
      if (fullScreen) {
          // Create window
          [self createWindow];
          // Swap player view
          [self swapPlayerViewHost];
          // Make view visible
          [self.playerWindow makeKeyAndVisible];
          _fullScreen = YES;
      }
      else {
          [self restorePlayerViewPosition];
          _fullScreen = NO;
      }
  
  }
  </code></pre>