我们有两个 UIViewController
和一个 UINavigationController
。
在 viewWillAppear(_ animated: Bool)
中的第一个 VC 中,我们做:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if #available(iOS 11.0, *) {
navigationController?.navigationBar.prefersLargeTitles = true
navigationController?.navigationItem.largeTitleDisplayMode = .always
}
....
在第二个 VC 中,我们在 viewWillAppear(_ animated: Bool)
中停用了该行为:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if #available(iOS 11.0, *) {
navigationController?.navigationBar.prefersLargeTitles = false
}
...
第二个 VC 的过渡动画是平滑的,同时点击自动生成的后退按钮导致导航 Controller 标题创建一个奇怪的 jump to large title
而不是正常的 grow to large title
动画,例如消息应用程序中的动画。
如果我点击标签栏图标作为“后退”操作,它会执行正确的过渡动画。
知道是什么导致了这个问题,或者我该如何解决它?
最佳答案
在第二个 View Controller 上将 largeTitleDisplayMode
设置为 .never
您不需要将 prefersLargeTitles
设置为 false
。
为了澄清这里的事情,您必须直接为 View Controller 的 navigationItem
设置 largeTitleDisplayMode
,而不是导航 Controller !
self.navigationItem.largeTitleDisplayMode = .never // This fixes the issue
self.navigationController?.navigationItem.largeTitleDisplayMode = .never // This doesn't work / Title will stay large
关于ios - 具有大标题跳转的后退按钮动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46318109/