title: Prevent AlertView from auto rotating
body: <p>The launch page of my app is set to <em>portrait</em> only with this little bit of code:</p>
  
  <pre><code>- (NSUInteger)supportedInterfaceOrientations
  {
      return UIInterfaceOrientationMaskPortrait ;
  }
  </code></pre>
  
  <p>When the app launches a <code>UIAlertView</code> appears for username and password entry.
  The method to display it is called from <code>viewWillAppear</code>.</p>
  
  <p>This worked fine for <em>iOS6</em> but since <em>iOS7</em>, if I switch the device to landscape, the main view remains in portrait but the the alert view and keyboard rotate to landscape.
  A further bizarre quirk is that when I switch back to portrait, only the keyboard switches back (in truncated form), leaving the alert frozen in landscape mode:</p>
  
  <p><img src="https://i.stack.imgur.com/sEF5G.png" alt="enter image description here"></p>
  
  <p>Can anyone tell me how to prevent this?</p>
  
  <p><strong>-EDIT-</strong></p>
  
  <p>The autorotate code is called in a separate category:</p>
  
  <pre><code>@implementation UINavigationController (Orientation)
  
  -(NSUInteger)supportedInterfaceOrientations
  {
      return [self.topViewController supportedInterfaceOrientations];
  }
  
  -(BOOL)shouldAutorotate
  {
      if (UIInterfaceOrientationIsLandscape([[UIDevice currentDevice] orientation])) return NO;
      else return YES;
  }
  </code></pre>
  
  <p>@end</p>
  
  <p><strong>-EDIT 2-</strong></p>
  
  <p>I've also tried creating a Category on <code>UIAlertView</code> but it's never called:</p>
  
  <pre><code>@implementation UIAlertView (Orientation)
  
  -(NSUInteger)supportedInterfaceOrientations
  {
      return UIInterfaceOrientationMaskPortrait;
  }
  
  -(BOOL)shouldAutorotate
  {
      return NO;
  }
  </code></pre>
  
  <p><strong>-EDIT 3-</strong></p>
  
  <p>I'm not sure how relevant this is but here's the code for showing the alert:</p>
  
  <pre><code>- (void)alertWithMessage:(NSString *)theMessage
  {
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Login"
                                                      message:theMessage
                                                     delegate:self
                                            cancelButtonTitle:@"Login"
                                            otherButtonTitles: nil];
  
      [alert setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
      UITextField *nameField = [alert textFieldAtIndex:0];
      [alert show];
  }
  </code></pre>