title: Allow video on landscape with only-portrait app
body: <p>I have a UIWebView included in a UIViewController which is a descendant of UINavigationController. It looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/EUKRgm.png" alt="Main view"></p>
  
  <p>The app is portrait only. When I play the video I want the user to be able to rotate the device and see the video in landscape mode. I use this code to allow it:</p>
  
  <pre><code>- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
  {
      id presentedViewController = [self topMostController];
      NSString *className = presentedViewController ? NSStringFromClass([presentedViewController class]) : nil;
  
      if ([className isEqualToString:@"MPInlineVideoFullscreenViewController"] ||
          [className isEqualToString:@"MPMoviePlayerViewController"] ||
          [className isEqualToString:@"AVFullScreenViewController"]) {
          return UIInterfaceOrientationMaskAllButUpsideDown;
      }
  
      return UIInterfaceOrientationMaskPortrait;
  }
  
  - (UIViewController *)topMostController {
      UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
  
      while (topController.presentedViewController) {
          topController = topController.presentedViewController;
      }
  
      return topController;
  }
  </code></pre>
  
  <p>And then in my UINavigationController (so when the video finishes the view is not presented in landscape but only in portrait):</p>
  
  <pre><code>- (BOOL)shouldAutorotate
  {
      return NO;
  }
  
  - (NSUInteger)supportedInterfaceOrientations
  {
      return UIInterfaceOrientationMaskPortrait;
  }
  
  - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
  {
      return UIInterfaceOrientationPortrait;
  }
  </code></pre>
  
  <p>Everything works perfectly:</p>
  
  <p><img src="https://i.stack.imgur.com/vNc3em.png" alt="Video portrait"> <img src="https://i.stack.imgur.com/E78b6m.png" alt="Video landscape"></p>
  
  <p>But then the video is done playing (or the user taps ‘Done’) and the screens return to the underlying view, this is what happens:</p>
  
  <p><img src="https://i.stack.imgur.com/eQq3Tm.png" alt="Navigation bar issue"></p>
  
  <p>As you can see, the navigation bar slips under the status bar.
  Additionally, I get a lot of auto-layout errors in the logs: <a href="http://pastebin.com/09xHzmgJ" rel="noreferrer">http://pastebin.com/09xHzmgJ</a></p>
  
  <p>Any idea about how to solve this?</p>