Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've done a little testing, and although I don't like the method, it's quite easy to do.</p> <p>Having looked for a private method that may have worked, I couldn't find one. All I found was:</p> <pre><code>@property BOOL forceFullHeightInLandscape; - (BOOL)isMinibar; </code></pre> <p>There is no setter for <code>-isMinibar</code>, so we can't set that. I guess that it returns a value based on its height. Also, <code>forceFullHeightInLandscape</code> was set to <code>NO</code>, however it still didn't adjust its height.</p> <p>While changing the <code>autoresizingMask</code> to include <code>UIViewAutoresizingFlexibleHeight</code>, the view <em>did</em> resize to be smaller, but now it was too small. However, <code>-isMinibar</code> suddenly returned <code>YES</code>. So that made me think of just letting the view resize itself, adjusting it to the right height.</p> <p>So there we go, a method that works, even without private API calls:</p> <pre><code>- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [self.navigationBar performSelector:@selector(sizeToFit) withObject:nil afterDelay:(0.5f * duration)]; } </code></pre> <hr> <p>One thing you'll have to deal with is that the views below the bar won't get adjusted to the smaller bar, so that there will be a gap between the bar and the views below. Easiest way to solve this is to add a container view, just like the case with a <code>UINavigationController</code>. You'd come up with something like:</p> <pre><code>- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [self performSelector:@selector(resizeViewsForNavigationBar) withObject:nil afterDelay:(0.5f * duration)]; } - (void)resizeViewsForNavigationBar { [self.navigationBar sizeToFit]; // Resize containerView accordingly. CGRect containerViewRect = self.containerView.frame; containerViewRect.origin.y = CGRectGetMaxY(self.navigationBar.frame); containerViewRect.size.height = CGRectGetMaxY(self.view.frame) - containerViewRect.origin.y; self.containerView.frame = containerViewRect; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload