How to create a view above navigation bar or other

2019-09-12 03:31发布

问题:

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:

回答1:

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.



标签: ios swift uiview