Support bars with equal height
I have two pages in my application, one is embedded UINavigationController
and the other is not. The page that is not in UINavigationController
has UINavigationBar
one that I dragged and dropped and set its prompt to an empty line to slightly increase its height. However, this causes it to be slightly taller than the page embedded in UINavigationController
. Here's the side image:
If I set the prompt on the left page navigation bar, the height gets too high. When I go to the storyboard inspector, I see that the height should be 74:
Does anyone know how to artificially make a panel on a page inline at UINavigationController
the same height as the one that's not?
source to share
This situation is common for others who have added UINavigationBar
manually (i.e. not through embedding inside UINavigationController
).
The general UINavigationBar
would have a height of 44 points
The problem lies in the 20 percent gap above manually added UINavigationBar
.
In the inline version, the break (assuming it exists) has the same background color as UINavigationBar
. When you add an invitation, it adds 30 items expanding upward. So instead of 20 + 44 = 64 points, you now have 74 points. And it embedded UINavigationBar
has 64 points. The difference is 10 points. And for the same reason adding "" ( space
) on embedded UINavigationBar
will cause the height to be higher than 74 points
.
I think it would be best to embed another one ViewController
inside new UINavigationController
. iOS is smart enough to treat it as if there was only one NavigationController
, not two. The user won't make any difference. As for the programmer, you need to take into account extra UINavigationController
if you need to find program code second ViewController
.
source to share
I was able to answer my own question.
I just changed the height programmatically in the custom subclass UINavigationController
:
override func viewDidAppear(_ animated: Bool) {
let bounds = self.navigationBar.bounds
self.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: 74)
}
source to share
Although you have already answered your own question, AFAIU height difference is a query result in one case, but not in the other. So what's wrong with adding an empty line prompt
for the ViewController inside UINavigationController
with UINavigationItem
, for example:
self.navigationItem.prompt = "";
If you have many view controllers inside UINavigationController
and don't need to explicitly specify the prompt in each, you can use or to set it in the same place for all child controllers.UINavigationControllerDelegate
willShow
didShow
This should be much more robust than your approach, as the height of the nav bar is not really the same across all devices and all device orientations (AFAIR iPad portrait and landscape are different), with Apple being able to change it between iOS versions.
source to share