0
votes

I have a toolbar at the top and at the bottom both set in the window. I am also using a UINavigationController. So I want to hide the nav bar as well. I found this question:

Persistent UIBarButtonItem in UIToolbar?

So in the app delegate I did:

[window addSubview:navigationController.view];
CGRect frame = navigationController.view.frame; // What is this view???
frame.size.height -= (topToolBar.frame.size.height + bottomToolBar.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height);
frame.origin.y += topToolBar.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height;
navigationController.view.frame = frame;
[navigationController setNavigationBarHidden:YES];

The toolbars are linked in IB. This is what you can see:

  • The status bar. OK.
  • Half the top toolbar
  • The nav bar which obscures the bottom half of the top toolbar and a bit of the loaded view.
  • Your first view with a small portion at the top hidden by the nav bar.
  • The bottom toolbar is OK.

setNavigationBarHidden just seems to move the nav bar out of the way. I can achieve what I want by explicitly setting hidden=YES on the nav bar (or a category on UINavigationBar and overriding drawRect).

The view on the nav controller is apparently a UILayoutContainerView. This appears to be undocumented.

So:

  • Is this a good method? May it get rejected?
  • Why do I get this overlapping behaviour with the nav bar?
1
I may get voted down for this comment, but: why mess around with UINavigationController? It is a very well working piece of UI component. If you don't need its functionality, just create your own views and slide them in or out using an animation.Krumelur
At first I did not have any toolbars and using UINavigationController and hiding the UINavigationBar was the easiest way to go. I got the view management and transitions for free. Now I am just curious about how this all works.Megasaur

1 Answers

1
votes

I found this solution works (without overlapping the navigation bar)

CGFloat height = [self.toolbar frame].size.height;
CGRect rootBounds = self.window.rootViewController.view.bounds;
CGRect frame = CGRectMake(0, CGRectGetHeight(rootBounds) - height, CGRectGetWidth(rootBounds), height);

[self.toolbar setFrame:frame];
[self.navigationController.view addSubview:self.toolbar];