title: how to set orientation in Portrait only?
body: <p>I want to set UIViewController in Portrait, I tried to add</p>
  
  <pre><code>- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
      return UIInterfaceOrientationPortrait;
  }
  
  - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
      return UIInterfaceOrientationMaskPortrait;
  }
  
  - (BOOL)shouldAutorotate {
      return [UIApplication sharedApplication].statusBarOrientation != UIDeviceOrientationPortrait;
  } 
  </code></pre>
  
  <p>But when I take my phone in Landscape, then enter this UIViewController,</p>
  
  <p>I will run into Landscape first, then rotate to portrait!</p>
  
  <p>but I don't want it shows landscape, I want it show portrait immediate,</p>
  
  <p>Is there any wrong setting?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I called the error ViewController "vcA",  it present from "vcB"</p>
  
  <p>in vcB's <code>viewDidAppear</code>, I called</p>
  
  <p><code>[self presentViewController:vc animated:NO completion:nil];</code></p>
  
  <p>then vcA will show in landscape(if vcB was in landscape),</p>
  
  <p>if add a few delay like:</p>
  
  <pre><code>dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
      [self presentViewController:vc animated:NO completion:nil];
  });
  </code></pre>
  
  <p>it will show portrait, but I do not know why it happen!</p>
  
  <p><strong>ANSWER</strong></p>
  
  <p>Finally, I found root cause!</p>
  
  <ol>
  <li><p>when I launch app, it stay in Portrait mode,</p></li>
  <li><p>After launch, vcB is first VC I called,</p></li>
  <li><p>Phone stay in landscape, so when <code>viewDidAppear</code> in vcB, it call
  rotate to Landscape</p></li>
  <li><p>At same time in viewDidAppear, I also call <code>present:vcA</code></p></li>
  <li><p>So currently, view have to do both rotate to landscape and present
  vcA(should in Portrait!!)</p></li>
  <li><p>Then the bad situation happened!</p></li>
  </ol>
  
  <p><strong>Solution</strong></p>
  
  <p>Just disable rotate for first launch in "vcB", then in <code>viewDidAppear</code>, it will only call <code>present:vcA</code></p>
  
  <p>Thanks all a lot!</p>