【发布时间】:2017-04-07 06:57:57
【问题描述】:
当我使用 storyboard segue 推送到下一个视图时,它会为状态栏加载一个空间,即使下一个视图已将 prefersStatusBarHidden 设置为 false。
我也尝试过将UINavigationController 子类化并将prefersStatusBarHidden 设置为false,但视图仍然为它加载了一个空间。还将automaticallyAdjustsScrollViewInsets 设置为false。
加载的视图由一个UIViewController 组成,该UITableView 具有一个UITableView。 UIViewController 的背景颜色(用于测试)设置为橙色,表格视图的背景颜色设置为粉红色。这两种颜色都没有显示。
在 som 测试之后,在我看来 UINavigationController 为其根视图添加了一个空间,并在动画推送后删除了该空间。如果我将UINavigationController 的背景颜色设置为紫色,我会得到以下结果:
这表明它所推送的视图既没有被渲染,也没有处于正确的 Y 位置。我似乎无法找到这是为什么。
我的UINavigationController 包含在UIViewController 中,该UIViewController 有一个视图容器(rootViewController)。
每当请求加载根页面时,导航控制器都会以编程方式创建。这是代码:
/// Load a view controller with UINavigationController into the
/// rootViewController and display it
///
/// - Parameter viewController: The view controller to show
func loadViewControllerPage(_ viewController: UIViewController) {
let nav = UINavigationController(rootViewController: viewController)
// No bar, please
nav.isNavigationBarHidden = true
// Make the view get in there propperly
nav.willMove(toParentViewController: self)
addChildViewController(nav)
nav.view.willMove(toSuperview: rootViewController)
nav.view.frame = rootViewController.bounds
rootViewController.addSubview(nav.view)
nav.view.didMoveToSuperview()
nav.didMove(toParentViewController: self)
rootViewController.bringSubview(toFront: nav.view)
/* Test if this fixes the statusbar issue
nav.edgesForExtendedLayout = .all
nav.automaticallyAdjustsScrollViewInsets = false
nav.extendedLayoutIncludesOpaqueBars = false
*/
currentNav = nav
// Cleanup
for child in childViewControllers {
if let c = child as? UINavigationController, c != nav && c.view.isDescendant(of: rootViewController) && c != menuView {
c.removeFromParentViewController()
c.view.removeFromSuperview()
}
}
}
关于如何解决这个问题的任何建议?
【问题讨论】:
-
adjustScrollViewInsets可能会有所帮助 -
已经将
automaticallyAdjustsScrollViewInsets设置为false,抱歉我没有提到。
标签: ios uitableview uinavigationcontroller swift3 xcode8