title: Change interface orientation when back button is pressed
body: <p>My app accepts only portrait orientation, except for <code>MPMoviePlayerController</code>, which I want to allow user to change orientation.</p>
  
  <p>So, I subclassed <code>UINavigationController</code> and added the following code:</p>
  
  <pre><code>-(BOOL)shouldAutorotate
  {
      if ([[[self.viewControllers lastObject] presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]])
      {
          return YES;
      }
      else
      {
          return NO;
      }
  }
  </code></pre>
  
  <p>It works great, allowing only my <code>MPMoviePlayerViewController</code> to change orientation. The problem is that when user is in landscape orientation and presses the <code>done</code> button or playback ends, it pops the <code>moviePlayer</code> and goes back to the presentingViewController, but on landscape mode, causing a crash, since that view is not made for landscape orientation. </p>
  
  <p>I tried a few things to change back to <code>Portrait</code> but had no luck. I'm using storyboards, if that makes any difference. I would like to change the orientation back to portrait on <code>viewWillAppear</code>, or maybe getting the <code>done</code>button press and change the orientation there. </p>
  
  <p>UPDATE:</p>
  
  <p>Here is the updated code in my <code>UINavigationController</code>subclass:</p>
  
  <pre><code>-(BOOL)shouldAutorotate
  {
      return YES;
  }
  
  -(NSUInteger)supportedInterfaceOrientations
  {
      if ([[[self.viewControllers lastObject] presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]])
      {
          return UIInterfaceOrientationMaskAll;
      }
      else
      {
          return UIInterfaceOrientationMaskPortrait;
      }
  }
  </code></pre>
  
  <p>Now, if I do things in the following order from the view with the Play <code>button</code>.</p>
  
  <ol>
  <li>Rotate the device. (it calls the method but screen doesn't rotate since it is not <code>MPMoviePlayerController</code> class)</li>
  <li>Press the play <code>button</code>. (It presents the player already on landscape mode).</li>
  <li>Press the back button. (It pops the player and correctly shows the view on portrait mode)</li>
  </ol>
  
  <p>Now, if I change the order to:</p>
  
  <ol>
  <li>Press the play button. (holding the device on the regular portrait position).</li>
  <li>Rotate the device. (it rotates the movie player correctly showing the video).</li>
  <li>Press the back button. (it pops the player, but this time, the view is in landscape mode, which is not the expected behavior)</li>
  </ol>