Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationController within ViewController, gap at top of view

I'm working on a universal app, and I'm trying to share as much code as possible between the iPhone and iPad versions. I need to use a TabBarController as my root view controller and though I'd like to use a SplitViewController in each of the tabs, SplitViewController's docs say it needs to be the root view controller. So, with all of that in mind - understand that I'm attempting to place two navigation controllers side-by-side and (mostly) replicate the behavior/layout of a SplitViewController.

Everything works just fine, except for the layout of the views. When the app is started in portrait mode, everything functions and resizes/positions correctly when the device orientation changes.

portrait orientation

If the app is started in any orientation other than UIDeviceOrientationPortrait, the view displays with a 20 point gap/margin above the navigation controller. I've tried adjusting the frame at runtime with no perfect result. Adjusting the origin.y of the frame to -20 and increasing the height by 20 brings the view flush with the top of it's parent, but it leaves a 20 point gap at the bottom!

landscape orientation

like image 379
E-Madd Avatar asked Mar 03 '11 16:03

E-Madd


People also ask

What is a UINavigationController?

A container view controller that defines a stack-based scheme for navigating hierarchical content.

How do I know if Viewcontroller is visible?

The view's window property is non-nil if a view is currently visible, so check the main view in the view controller: Invoking the view method causes the view to load (if it is not loaded) which is unnecessary and may be undesirable. It would be better to check first to see if it is already loaded.

What is the difference between Viewcontroller and UIViewController?

Both are used for different purpose. A UIViewController class manages a ViewContoller which is responsible for actions that happen within that View controller. This class is aware of actions that happen on view controller, like ViewDidLoad, ViewWillApper, ViewDidAppear, ViewWillDisapper, ViewDidDisapper.

What is navigation stack in swift?

What is a navigation stack? “A navigation controller object manages its child view controllers using an ordered array, known as the navigation stack. The first view controller in the array is the root view controller and represents the bottom of the stack.


2 Answers

I solved this in my app by hiding then showing the navigation bar after adding the navigation controllers view. eg.

[parentView addSubview:navController.view];
[navController setNavigationBarHidden:YES];
[navController setNavigationBarHidden:NO];
like image 188
kevin Avatar answered Sep 28 '22 05:09

kevin


Oddly enough, what's helping for me in iOS 6 is subclassing UINavigationController and implementing this method:

- (BOOL)wantsFullScreenLayout {
    return NO;
}

Unchecking "Wants Full Screen" in my storyboard didn't do the trick, so I don't know what's different. This could certainly break in a future version of iOS. But for now, I'll take it.

like image 28
Becca Royal-Gordon Avatar answered Sep 28 '22 07:09

Becca Royal-Gordon