Making a nav controller work the same in iOS 6 and iOS 7

How can a navigation bar be supported in both iOS 6 and iOS 7 with a UIContainerView via a storyboard?

I am updating an iOS 6 app to iOS 7, but want to continue to support iOS 6. I have a main top level view that is embedded within a UINavigationController. The view within the navigation controller has a container view in it. I am using a storyboard to lay out the view.

On iOS 7 the navigation controller uses the entire screen, and I've set it up to put the container view content below the navigation bar. In iOS 6 the content of the view does not go under the navigation bar, so I have a blank gap below the nav bar.

Normally I would just reset the origin of the offending view on iOS6 (in ViewDidLoad or somesuch) and go on my way. However since my content is in a UIContainerView, I can't seem to change the frame after it loads. (I have tried this in prepareForSegue: when loading the UIContainerView. I'm open to having done this wrong? heh)

The closest I have found is using the following code under iOS 7 to make the nav bar opaque and keep the content out from under it, then using the entire space for my UIContainerView.

  // tell the view to not extend below this nav bar
  if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
    self.edgesForExtendedLayout = UIRectEdgeNone;

This solution works but has the side effect of showing the status bar as black (since it's more or less "blank" under the status bar). Alternatively, if I put the top edge of the container view below the status bar, on iOS 6 I have a big gap below the navigation bar.

I can eliminate the use of a navigation controller, but that seems a bit heavy handed in this situation and I'd like to use that as a last resort.

Answers


I've found the solution to this.

You need to set the barTintColor in iOS 7, which also seems to color the main status bar, as well as setting the nav bar to not be transparent like this:

mainController.navigationBar.barTintColor = [SRPRTabletHelpers customUserColor];
mainController.navigationBar.translucent = NO;

The non-transparency was the key, while setting the color sets not only the regular nav bar, but the color beneath the status bar as well.

I also needed to change my containerView top edge to be the full height of my view contained within the navigation controller, now that it is not transparent, and it works the same on both iOS6 and iOS 7.


While you mention to have already solved this, your method seems to require a lot of manual code and if checks. The iOS 7 UI Transition guide, in the Supporting iOS 6 chapter mentions another way: first design your interface for iOS7 as you have done, with your view extending below the navigation bar.

Then, in the interface builder open the size inspector for UI elements and modify the iOS 6/7 deltas. These values are applied when the storyboard is not run on iOS 7. For example, in your case you can select all your visual elements, then set the Y delta to -44, which is the standard navigation height. That will make the UI go up on iOS6, compensating the fact that the view doesn't go under the navigation bar.


Need Your Help

dynamically adding fields and content in jQuery

jquery

I'm trying to add fields dynamically to a web page so that a user can enter in additional amenities to a form. By clicking on the add amenity button I can add the fields just fine. However I cannot

symfony2 application, vagrant & ant: stty: standard input: Invalid argument

php ant symfony phpunit stty

I am trying to move my development environment (symfony2 application) from my windows 7 localhost to a virtual machine using vagrant and the default ubuntu 10.04 64 bit machine. Everything is set u...