【问题标题】:UIViewController under UINavigationBar?UINavigationBar下的UIViewController?
【发布时间】:2015-05-05 00:06:21
【问题描述】:

我有一个UINavigationController 和一个UIViewController 作为它的根视图控制器。

let rootVC = Page1ViewController()   // extends UIViewController
let nav = UINavigationController(rootViewController: rootVC)
presentViewController(nav, animated: true) { () -> Void in
}

问题是rootVC的内容出现在导航栏下。我试过了:

nav.navigationBar.translucent = false

这可行,但我希望导航栏是透明的,并且我希望 rootVC 的内容不会出现在导航栏后面。

我也试过了:

nav.edgesForExtendedLayout = UIRectEdge.None

但这不会改变任何事情。

如何获得一个透明的导航栏,滚动时内容在其下方滚动,但加载内容时不应出现在导航栏下方?

【问题讨论】:

    标签: ios objective-c swift uiviewcontroller


    【解决方案1】:

    删除这一行:

    nav.edgesForExtendedLayout = UIRectEdge.None
    

    并在 Page1ViewController 的 viewDidLoad 中添加这一行

    self.edgesForExtendedLayout = UIRectEdge.None
    

    希望对您有所帮助。让我知道它是否不起作用,我会帮助你。

    【讨论】:

    • 这可行,但现在我在状态栏后面有一个黑色背景。你也能解决这个问题吗?
    【解决方案2】:

    要解决您的UINavigationBar 下方出现黑盒的问题,您需要正确设置演示上下文。尝试将definesPresentationContext 上的UINavigationController 设置为NO。然后,这将使用 UIWindowUINavigationController 的父级作为演示上下文。

    【讨论】:

    • 我做了nav.definesPresentationContext = false但是没有效果。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-15
    • 1970-01-01
    相关资源
    最近更新 更多