In my app, I got a UINavigationController. Unfortunately, when I rotate the device and the interface orientation changes, the UINavigationBar doesn't change its height. In other iPhone applications, such as the Contacts.app, the navigation bar gets slightly less tall in landscape mode. It must be built-in, because if you take the navigation sample app from the XCode menu and add interface orientation to it, it does change the navigation bar's height properly.
How can I make the navigation bar resize like it does in all other iPhone apps I've seen?
Thanks to Joost I've added
to my custom UINavigationBar class. And set in :
Worked like a charm
Similar to Joost's answer, but putting the method in
willAnimateRotationToInterfaceOrientation
has a better animation effect thanwillRotateToInterfaceOrientation
. (There's no animation delay)I just had this error as well, and although it's probably not for the same reason I'd like to post it here to help anyone else that goofs.
If you're overriding any
willRotateToInterface
methods, remember to callsuper
I blanked on that, but once I saw the accepted answer it came to me.
I think this one is kind of similar to you and they have the code snippet:
iPhone: UINavigationBar with buttons - adjust the height
I think the behavior you want only happens when a navigation controller ( which represents the bars (navigation or toolbar)), is added to the window in the app delegate or presented by a tab bar, etc.
You can add a navigation bar via IB or code, it doesn't mean you have a navigation controller. My opinion is, create a navigation controller and initialize it with the view controller you're working in. Probably when the view rotates, the nav bar will shrink a little, the way you like.
Hope this helps
I've done a little testing, and although I don't like the method, it's quite easy to do.
Having looked for a private method that may have worked, I couldn't find one. All I found was:
There is no setter for
-isMinibar
, so we can't set that. I guess that it returns a value based on its height. Also,forceFullHeightInLandscape
was set toNO
, however it still didn't adjust its height.While changing the
autoresizingMask
to includeUIViewAutoresizingFlexibleHeight
, the view did resize to be smaller, but now it was too small. However,-isMinibar
suddenly returnedYES
. So that made me think of just letting the view resize itself, adjusting it to the right height.So there we go, a method that works, even without private API calls:
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
UINavigationController
. You'd come up with something like: