UINavigationBar 下的 UIViewController?

UIViewController under UINavigationBar?

我有一个 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

但这并没有改变任何东西。

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

删除此行:

nav.edgesForExtendedLayout = UIRectEdge.None

然后在 Page1ViewController 的 viewDidLoad 中添加这一行

self.edgesForExtendedLayout = UIRectEdge.None

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

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