Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationController bar covers its uiviewcontroller's content

I have a UIViewController, MyViewController, with a UIToolbar at the top. Using interface builder the doc outline looks like this:

View 
  - subview1
  - subview2
  - UIToolbar
     - Bar Button Item1
     - Bar Button Item2
     - Bar Button Item3

MyViewController is used throughout my app. Sometimes it's in a UINavigationcontroller, other times it's in a UIPopoverView.

When it appears in UINavigationController, the navigation bar covers up the UIToolbar and all other content near the top of View. In this screenshot you can see that the UIToolbar is completely covered up, and UIButton w/ an image of a green light bulb is partially covered.

According to the apple documentation

Any view that needs to be anchored to the top and just below the status bar (i.e. UIToolbar, UIButton, etc.) requires additional work for proper placement.

It proceeds to give a solution that simply uses constraints to move your VC's content down by x pixels, in my case the UIToolbar. This doesn't seem like a good solution because it assumes you always want the content moved down below the nav bar. In my case, I obviously don't since MyViewController is not always in a UINavigationController. When I use the constraint solution provided in these docs, the UIToolbar is oddly floating down x pixels unanchored from the top in all cases where MyViewController is not in a UINavigationController.

Am I missing something with how I am supposed to display a VC's content within a UINavigationController? Thanks so much.

like image 986
roro Avatar asked Dec 27 '13 23:12

roro


People also ask

What is a UINavigationController?

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

What is a navigation bar in IOS?

A navigation bar appears at the top of an app screen, enabling navigation through a hierarchy of content. A navigation bar also provides a natural place to display a screen's title — helping people orient themselves in your app or game — and it can include controls that affect the screen's content.

How do I change the navigation bar on my Iphone?

A user changes the navigation bar's style, or UIBarStyle , by tapping the “Style” button to the left of the main page. This button opens an action sheet where users can change the background's appearance to default, black-opaque, or black- translucent.


2 Answers

In iOS7, UINavigationBar has translucent property and views of child VCs of UINavigationViewController are underneath UINavigationBar by default.

If you don't need this translucent effect, turn off this property by using the following code.

self.navigationController.navigationBar.translucent = NO

You can also use @ldindu's way as well.

like image 156
Kyokook Hwang Avatar answered Oct 13 '22 12:10

Kyokook Hwang


If you are running on iOS 7.0 version then you need to set following property which is newly introduced in iOS 7.0 as follows

self.edgesForExtendedLayout = UIRectEdgeNone; 

as by default edgesForExtendedLayout property is set to UIRectEdgeAll that means the view controllers use full-screen layout by default.

like image 41
ldindu Avatar answered Oct 13 '22 13:10

ldindu