title: How do I get the navigation bar in a UINavigationController to update its position when the status bar is hidden?
body: <p>I have a <code>UINavigationController</code> with a visible Navigation Bar.
  I have one particular <code>UIViewController</code> which I'd like to hide the status bar when pushed into the navigation stack. Once this viewController is popped I'd like to show the status bar again.</p>
  
  <p>I'm hiding the bar in the <code>viewWillAppear</code> method of my <code>UIViewController</code> like this:</p>
  
  <pre><code>- (void) viewWillAppear:(BOOL)animated {
  
      [super viewWillAppear:animated];
  
      [self.navigationController setWantsFullScreenLayout:YES];
      [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];    
  }
  </code></pre>
  
  <p>Note that I'm setting <code>setWantsFullScreenLayout:YES</code> here for clarity, but I'm actually just setting this property in Interface Builder.</p>
  
  <p><strong>The problem:</strong>
  The navigation bar of the NavigationController doesn't move up to take the space of the now hidden status bar.</p>
  
  <p><strong>A hacky solution</strong>
  The only thing I found that worked to refresh the position of the nav bar was to hide it and show it again, like this:</p>
  
  <pre><code>[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
  [self.navigationController setNavigationBarHidden:YES animated:NO];
  [self.navigationController setNavigationBarHidden:NO animated:NO];
  </code></pre>
  
  <p>but this is clearly a hack, there has got to be a better way.</p>
  
  <p><strong>Other things I tried:</strong></p>
  
  <ol>
  <li><p>I tried calling the <code>[super viewWillAppear]</code> after hiding the status bar, i.e. at the end of my method.</p></li>
  <li><p>I tried setNeedsLayout on the navigationController.view like this:</p>
  
  <pre><code>[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];    
  [self.navigationController.view setNeedsLayout];
  </code></pre></li>
  </ol>
  
  <p>but that doesn't seem to work.</p>
  
  <p>Any help appreciated. 
  Thanks</p>