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

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.

Related

UIView inside UIScrollerView displays with -64 offset

I'm trying to create a form that will be larger than the screen size and I've decided to use a view inside a scrollerview, then I'm adding the rest of the UI widgets (textfields, buttons, etc.) inside the view.
The view displays and scrolls, but no matter what I try, it displays with a vertical offset of -64 below the navigation controller bar. Once there the view will happily scroll up down.
I want the view to anchored at the top, just below the navigation bar, and then scroll down.
I am using IB.
Lots of time researching and not many answers that have worked for me. UIScrollView seems to be like one of those dirty secrets the whole iOS world seems to avoid....
Thank you for your help.
You can fix this in the storyboard
1- Select the view Controller
2- GO to attributes inspector
3- Uncheck adjust scroll View insets
For your view controller, in the storyboard uncheck the option to extend edges under top bar.

Hide UINavigationBarController in first view controller and AutoLayout

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.

Top Layout Guide won't start at top of screen in Xcode 6 storyboard

I have 2 view controllers setup identically in a Storyboard. On one, the top layout guide goes all the way to the top (under the status bar), on the other the top layout guide starts just below the status bar.
On both view controllers, I have Extend Edges Under Top Bars (checked) and Adjust Scroll View Insets ->unchecked (not that I'm using a scroll view here).
I can't figure out why these are different in the storyboard, and thus at run time one view controller looks like the way it was designed, the other does not because items with constraints to that top layout guide will be 20px wrong.
Help.

What is the proper way to add a view to a view controller and make it cover it completely through rotations using Auto Layout?

Say I have a UIViewController and I want to add a red UIView atop it that covers its view completely using Auto Layout.
My first instinct was to pin it to every edge of the view controller's view, but due to the iOS 7 nature of view controller views extending underneath the nav bars, pinning it with a constant of 0 doesn't put it under the nav bars. And if I put -64 to cover it in portrait, that's not the correct constant for landscape as the nav bar is shorter.
How should I be implementing this?
Make sure your view is pinned to the top of the super view, not the top layout guide. It sounds like it's currently pinned to the top layout guide.
If it is pinned to the top layout guide, the best way to fix it is to delete the constraint, select the view, click the "Pin" tool at the bottom right of IB, and then select the top with a setting of zero.
This works fine in Xcode 5.1.1, but was a little buggy in earlier versions. Control+Drag onto the view generally forces you to select the top layout guide instead of the top of the view.

ios 7 UINavigationBar is above content when using Auto Layout

I am using Auto Layout in a storyboard to position a UICollectionView. I have created a vertical spacing between Top Layout Guide and the CollectionView. But the collection view still starts underneath the navigation bar. Even the prototype cell also has extra padding. Please see images below.
Interface Builder:
Simulator View:
The content should start below the navigation bar but as the user scrolls the content should go under the navigation bar. How do I accomplish this?
In your storyboard go to View Controller properties, and make sure that Under Top Bars option is unchecked.
Also in most cases you want to have opaque navigation bar.

Resources