Womble Womble - 1 year ago 106
iOS Question

iOS UINavigationController-like behaviour in a partial screen area (2016)

(I have read other questions and answers on this topic, but most are very old and do not relate to iOS 9 or 10.)

The app design calls for the top half of the display to always contain the same content. (An image being edited by the user.)

The bottom half of the display needs a

. When a
is tapped, the bottom section needs to transition to a new
with slide-on animation, similar to how
push segues work.

Problem: only the bottom view needs to transition to the new view controller(s), and back again. The upper half of the view hierarchy needs to remain unaffected. For this reason, I can't place everything inside a
, and I can't have a
at the top of the screen.

Question: what approach should I take in such a situation, where I need only one
hierarchy to transition in push-segue fashion, but not anything else? Thanks.

Edited with Solution

Solution follows, for those following along at home.

Storyboard layout


Push Segue

Answer Source

Yes, you can actually use a UINavigationController for the bottom half.

If you are using Storyboards, the easiest way to do this is to use a container view for each part of the screen which you then can embed a UIViewController in for the top part and a UINavigationController in for the bottom part. If you are doing this programmatically, just add the view controllers as child view controllers to your app's initial view controller (see this answer for more info) which is essentially what the Storyboard will do for you automatically when using a container view.

As a child view controller, the UINavigationController will act independently from the top UIViewController and should behave as expected.

I recommend the programatic approach for the following reasons:

  • It helps you understand the inner workings of child/parent view controllers much better which will likely save you a significant amount of debugging time down the line.
  • It makes adding/removing/swapping child view controllers as simple as a few lines of code. Trying to do this with Storyboards is notoriously hacky and cumbersome.
  • It's much easier to keep track of changes using GIT (most mid-size/larger companies actually prohibit Storyboards for this very reason)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download