0

I would like to have a view above the navigation bar, or above any screen content if there isn't a navigation bar on that screen, so that it essentially reduces the height of everything else and doesn't cover any content. I also would like this view allow interaction (i.e. if its tapped, it would do something).

I have tried UIApplication.sharedApplication().keyWindow?.addSubview(view) but that just overlays the view.

Here is a visualization: View above navigation bar.

hoffware
  • 205
  • 6
  • 19

1 Answers1

4

Don't think of it in terms of above, think of it as beside - a sibling view.

So, create your own root view controller with that view and a container view below it, then add your 'normal' root navigation controller (or whatever) as a child view controller into the container view.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • I went with this way and it works out pretty nicely. I was initially running into issues with the navigation controller in the container view not reacting to the status bar, but I just had to fiddle with autolayout to get it working. Now, when I toggle the red bar at the top, the navigation bar moves correctly, but the nav controller's child view doesn't get pushed all the way down. I might have to ask another question, but before I do, any quick thoughts on why that would be? – hoffware Feb 09 '16 at 10:29
  • is anything in a scroll view auto adjusting insets that you don't actually want? – Wain Feb 09 '16 at 10:38
  • Yeah, it's a table view that doesn't seem to be moving as far down as the navigation bar above it. – hoffware Feb 10 '16 at 04:26
  • You need to turn off auto inset on the view controller – Wain Feb 10 '16 at 07:49
  • Okay, I'll look into that. If you're bored, I have another SO question that I just submitted because of a problem I've run into going down this route: http://stackoverflow.com/questions/35309298/in-a-container-view-a-navigation-controllers-navigation-bar-not-resizing-to-in – hoffware Feb 10 '16 at 08:11
  • 1
    This is the best answer in the whole SO!! I've struggled with moving ViewController frames, while adding a subview to the windows, but they broke as soon as a modal view appeared (a Picker/SMS composer/incoming phone call).. this one is the best. And it's the way it's meant to behave. – zontar Aug 29 '17 at 19:34