iPhone 6 Plus上的奇怪的UINavigationBar行为

时间:2014-12-27 07:06:22

标签: xcode swift ios8

我正在开展一个个人项目,并且正在感受应用程序可能的导航流程。

我正在使用UIPageViewController在多个视图控制器之间切换。

我看到的问题只发生在iPhone 6 Plus上。这是一个截图:

enter image description here

正如您所看到的,当我从一个视图控制器滑动到" next"一," next"的导航栏视图控制器似乎比它应该是20点(状态栏存在)。当它完全加载时,高度会跳到正确的大小。

这仅在iPhone 6 Plus上发生,并且仅在首次启动时发生。

任何见解/帮助都将受到赞赏。

1 个答案:

答案 0 :(得分:2)

我想有几种方法可以解决这个问题(现在我已经开始工作了)。

最简单的解决方案是将pageViewController.view的框架设置为帐户状态栏。

self.pageViewController.view.frame = CGRectMake(0.0, 20.0, self.view.frame.size.width, self.view.frame.size.height - 20.0)

由于这是我在特定情况下所需要的全部内容,我对结果非常满意。

另一种解决方案是在您要添加pageViewController.view的视图上以编程方式设置(添加)约束。

    override func updateViewConstraints() {
    super.updateViewConstraints()

    self.pageViewController.view.setTranslatesAutoresizingMaskIntoConstraints(false)
    self.view.addConstraint(NSLayoutConstraint(item: self.pageViewController.view, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Top, multiplier: 1.0, constant: 20.0))
    self.view.addConstraint(NSLayoutConstraint(item: self.pageViewController.view, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: 0.0))
    self.view.addConstraint(NSLayoutConstraint(item: self.pageViewController.view, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Leading, multiplier: 1.0, constant: 0.0))
    self.view.addConstraint(NSLayoutConstraint(item: self.pageViewController.view, attribute: NSLayoutAttribute.Trailing, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Trailing, multiplier: 1.0, constant: 0.0))
}

上面的示例覆盖了updateViewConstraints()函数。

希望这可以帮助一路上的人。如果有更好的解决方案,请告诉我。

谢谢!