Hide UINavigationBarController in first view controller and AutoLayout - ios

I have a design for an app with 3 screens where the
A) initial screen shall not show top navigation bar
B) second screen shall show top navigation bar (with a nav back button to A)
C) third screen shall not show top navigation bar (but a normal button back to B)
I chose to embed the view controllers in a navigation bar.
But doing so the AutoLayout constraints on the first view controller poops out plenty of warnings - because the embedded UIViews are pinned to the top bar - which is really annoying.
Of course if I "hide" the navigation bar in the storyboard designer, I am no longer able to add the required buttons for by B screen.
An alternate option COULD be to implement the navigational properties of my app all manually, but I really want to avoid doing this.
What is the preferred (best practice) solution to this?

Its Too simple...
you just set hidden attribute of navigation controller in viewWillAppear ex:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden=YES/NO; //as per your requirement
}

As noted in #SonuPatel answer, you can set the navigation bar to hidden relatively easily. For layout:
In controllers A and C, make your top layout offsets relative to the view and not the top layout guide. This will make them layout under the navigation bar when it is not visible. Hidden items usually still contribute to layout, so the topLayout guide is unaffected by it being hidden.
In controller B, make your top layout relative to the top layout guide to keep it below the navigation bar.
For a UITableViewController, you can get this for free by selecting Extend Edges Under Top Bars in the attribute inspector.

Related

Extra space at the bottom of the view controller?

I am using a storyboard with a custom tab bar controller.
When view controllers are added through the storyboard references, with a container(embedded) view, it creates an extra space at the bottom of the view controller, ie just above the tab bar.
The dimension of the space seems to be the same as that of the tab bar height. Is there any solution for this issue?
Check the following in storyboard :
Extend Edges
1. Under Opaque Bars
2. Under Bottom Bars

iPhone X - Hidden status bar pushes Navigation Bar upwards

I'm testing iPhone X behavior using the Xcode simulator. For some odd reason, if I'm hiding the Status Bar the Navigation Bar pushed upwards causing the title to completely disappear and cutting the left and right buttons. This is happening only on the iPhone X.
Illustration:
How can I hide the status bar and keep the Navigation Bar at a visible position?
UPDATE:
Sample project for your convince:
https://drive.google.com/file/d/0B5qJARV-Oc9ra1hvZkpXZm9lRUE/view?usp=sharing
One solution is to embed the navigation controller inside a container view controller which is properly constrained to the safe area.
Just create another view controller and drag a "Container View" from the Object Library. This view has top, bottom, leading, and trailing constraints to the safe area, all with constants equal to 0. If you control-drag from the container view to the navigation controller, you'll get an option to set an "embed segue" which will embed the selected view controller as a child view controller.
I set the status bar to be hidden on the new view controller I created, and it works fine.
This feels like something that UINavigationBar should handle automatically, but this workaround seems like it should work pretty well.
Another note: if you change the color of the navigation bar, you'll also need to create another view above the container view, and change its color to match the color of the navigation bar.
I, for a small app, changed from using a Push to a Modal segue and adding in my own navigation bar. I used Push because it looks good, and already had a Modal for another part, which I wanted to animate differently for style reasons.
For smaller apps this may be the quickest and easiest solution, but my next update I need to use the navigation controller. For that I think I'll switch on the status bar, which is no big deal for me and allows it to work.
I think you need to use "safeAreaLayoutGuide" new update in iOS 11
Apple has provided us with the necessary APIs to get around the unsafe regions of this iphone x. We do this by using the new safeAreaLayoutGuide anchors in our code
safeAreaLayoutGuide

Remove the gray bar at the bottom of view controller - iOS

The image shows the View controller and the bar I want to remove. And also the structure of the view controller:
Someone told me how to remove the grey bar present at the bottom of the view controller as shown in the image. Unable to select and delete the bar. When I try to add the tab bar in that place, it goes behind the grey bar and becomes invisible.
What do your simulated metrics look like?
Can you get rid of the bar by changing the bottom setting?
Couple of things - if you are using autolayout, just make a constraint to the bottom of the container, with 0 value for the constraint. That will take it to the bottom. Second thing I would add is a zero size table view footer to the tableview.
This is a toolbar that comes with the UINavigationController that the View Controller is embedded in. Assuming you have a Navigation Controller on the storyboard connected to the view controller, select it and in the attributes inspector deselect "Shows Toolbar". If you want to do this in code you can get and set isToolbarHidden on a UINavigationController instance.

ViewController - main view elements at (0,0) are obscured by navigation bar

I have a simple case where I am pushing a new viewcontroller onto a navigation controller stack. This VC uses a xib and has a UISearchBar that is constrained to the top and left 'container' which in this case is simply the main View.
When I push this VC on the stack the search bar is not seen. This is because the nav bar rests on top taking up the first 50 or so y points of the device screen. (starting after the status bar presumably).
If I set the top container auto-layout constraint to 50, or some y-offset sufficient to counteract the height of the nav bar, I will see the search bar.
I am working on a project where I am pushing VC's onto a nav stack of a UINavigationController I did not create. I am wondering what reasons could lead to this (what i would call buggy) behavior. My understanding was that any viewController in a navController would have it's main view's frame adjust in the presence of nav/status/tab bars. What can I do to ensure that origin (0,0) starts at screen origin + status bar height + nav bar height? Furthermore, I would also like my VC's mainView's lower bound to end at the top of the tab bar also present on screen. I have looked into various UIView and ViewController properties and have not found a satisfying solution.
If you use xib file for designing your view controller, you should add this code to your viewDidLoad method:
self.edgesForExtendedLayout = UIRectEdgeNone
This line will make your view controller's view is laid out under the navigation bar.
Conventionally, any new UIViewControllers are done on storyboards and some developers hook up segues between the first and second UIViewController. The reason for this is because by implementing a pushing segue, the secondUIViewController over the first one, the second one will inherit whatever properties the first one had (such as navigation bars, toolbar, tabbar) and it shows on the storyboard immediately.
So then it will be easier to work on the second UIViewController knowing how much space to allocate to UINavigation or UITabbar.
If your VC is done on an XIB interface instead of being hooked to the UINavigationController controlled stack of previous ViewControllers, then I am guessing you are not seeing the space that UINavigationBar and UITabBar supposedly takes up on your interface?
Perhaps you could try setting the constraints to begin at 64 points below the Top Layout Guide (to make space for UINavigationBar) and 49 above the Bottom Layout Guide (to make space UITabbar).

In Xcode 5 in a GLKViewController in IB what are the Top/Bottom Layout guides for?

In Xcode 5 in a GLKViewController in IB what are the Top/Bottom Layout guides for? I've been reading through docs and can't seem to find it anywhere.
These are not specific to GLKViewController -- you'll see them in any view controller.
In iOS 7, views extend underneath the transparent status, navigation, and tab bars (if present) by default. Because you probably don't want your subviews ending up underneath these bars, the layout guides provide an easy way to set up layout constraints relative to wherever those bars end up.
For example, say you want a button to appear 20pt below the navigation bar. Where before you'd make a constraint between the button and the top of the view, you can now make a constraint between the button and the top layout guide. That view in the nib isn't responsible for setting whether the navigation bar is shown or how tall it is -- those things are controlled by the view controller that presents the view at run time -- so constraining to the top layout guide makes sure your button is in the right place regardless of how the view is presented.

Resources