title: How do I programmatically set device orientation in iOS 7?
body: <p>I am working on an iPad app, using AutoLayout, where if the user enables a certain mode ("heads-up" mode), I want to support only portrait (or portrait upside down) orientation, and furthermore, if the device is in landscape, I'd like to automatically switch to portrait mode.</p>
  
  <p>In the top view controller, I have the following:</p>
  
  <pre><code>- (NSUInteger) supportedInterfaceOrientations {
      if (self.modeHeadsUp) {
          return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
      } else {
          return UIInterfaceOrientationMaskAll;
      }
  }
  
  - (BOOL) shouldAutorotate {
      return TRUE;
  }
  </code></pre>
  
  <p>Based on answers I've seen elsewhere here, the answer <em>seems</em> to be that I should use "application setStatusBarOrientation". Therefore, in the method where the user has selected "heads-up" mode, I have included:</p>
  
  <pre><code>    UIApplication *application = [UIApplication sharedApplication];
      [application setStatusBarOrientation:UIInterfaceOrientationPortrait
                                  animated:YES];
  </code></pre>
  
  <p>However, this simply doesn't seem to do anything. While I can physically move the device to get it to rotate into portrait, it doesn't do so automatically.</p>
  
  <p>In fact, when in landscape mode after running the above code to attempt to programmatically set the orientation, when I query the application "statusBarOrientation" with the following code, it remains at "4" for landscape:  </p>
  
  <pre><code>UIApplication *application = [UIApplication sharedApplication];
  int orientation = [application statusBarOrientation];
  self.movesTextView.text = [NSString stringWithFormat:@"ORIENTATION %d", orientation];
  </code></pre>
  
  <p>It seemed like maybe autolayout wasn't being triggered with the setStatusBarOrientation, so I attempted to add this code after, to no effect:</p>
  
  <pre><code>    [super updateViewConstraints];
      [self.view updateConstraints];
  </code></pre>
  
  <p>I realize Apple wants to leave device orientation in the hands of the user. However, I'd like to be able to support landscape mode when not in "heads-up" mode. </p>
  
  <p>Am I missing something to be able to force orientation change?</p>