如何在导航栏或其他屏幕内容上方创建视图? [英] How to create a view above navigation bar or other screen content?
问题描述
如果该屏幕上没有导航栏,我希望在导航栏上方或任何屏幕内容上方有一个视图,这样它实质上会降低其他所有内容的高度并且不覆盖任何内容.我也希望这个视图允许交互(即如果它被点击,它会做一些事情).
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).
我试过了UIApplication.sharedApplication().keyWindow?.addSubview(view)
但这只是覆盖了视图.
I have tried
UIApplication.sharedApplication().keyWindow?.addSubview(view)
but that just overlays the view.
这是一个可视化:
推荐答案
不要从上面的角度考虑,把它当作旁边 - 一个兄弟视图.
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.
这篇关于如何在导航栏或其他屏幕内容上方创建视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!