iOS 11设置prefersLargeTitles时发生异常

时间:2018-01-12 08:36:04

标签: ios swift

enter image description here

标题导航栏效果,返回动画不顺畅的问题。

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.navigationController?.navigationBar.prefersLargeTitles = true
}

我设置了推送页面

override func viewDidLoad() {
    super.viewDidLoad()
    self.title = "Detail"
    view.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
    self.navigationController?.navigationBar.prefersLargeTitles = false
}

enter image description here

系统设置页面,返回动画非常流畅。 甚至还有缩放动画,这应该是Apple API包含的。

1 个答案:

答案 0 :(得分:1)

我建议您在退出第二个视图控制器时尝试设置viewWillDisappear方法:

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    self.navigationController?.navigationBar.prefersLargeTitles = true
}

然后,在viewWillAppear中执行此操作:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.navigationController?.navigationBar.prefersLargeTitles = false
}

这将确保在不同风格上的平滑过渡