导航栏的宽度随机加倍。您可以在打印语句中看到这一点。一个在 Page1ViewController.viewDidLoad() 中打印 (self.navigationController.navigationBar) —— 您会在其中看到导航栏是预期的宽度。然而,第二个和第三个打印(分别是 viewWillAppear 和 viewDidApepar)你可以看到宽度是原始宽度的两倍。
我不知道为什么会这样...有人有什么建议吗?
这是 git 项目:https://github.com/bhowell2/iOSNavBarDoublingBug
项目结构:
TabBarController,它有一个 contentView 和一个 tabBarView。它们是使用 AutoLayout 约束设置的(在将它们添加为 Root View 的 subview 后调用)。
TabBarController 加载 NavigationController,它被赋予了 PageViewController 的 Root View Controller (它有 2 个 TableViewController 和 1 个 UIViewController)。
我还验证了仅将“常规”UIViewController 作为 PageViewController 的页面时失败。
此外,在 iOS 7.1 中运行此程序时,您会看到一些更奇怪的行为 - 一半的窗口被切断..(更改 TabBarViewController.contentView.clipsToBounds = false/true)以稍微改变此行为,其中导航栏“似乎有效”,但其余的 View 被切断了..
使用 XCode 6.2
最佳答案
你没有设置必要的约束,我只是删除了所有约束并尝试使用 Spring 和其他东西:
for view in [ tabBarView, contentView, navController.view, pageViewController.view ] {
view.frame = self.view.bounds
view.setTranslatesAutoresizingMaskIntoConstraints(true)
view.autoresizingMask = .FlexibleWidth | .FlexibleHeight
}
一切看起来都不错。
关于ios - NavigationBar 宽度在页面 View Controller 中随机加倍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29066953/