返回导航到根视图控制器后,折叠的大标题导航栏变得展开
Posted
技术标签:
【中文标题】返回导航到根视图控制器后,折叠的大标题导航栏变得展开【英文标题】:Collapsed large title navigation bar becomes expanded after back navigation to root view controller 【发布时间】:2020-12-03 18:30:11 【问题描述】:我有 UIViewController 和垂直 UIScrollView,它有 UIView 作为它所有子视图的容器。这是我的 scrollView 和 contentView 约束:
scrollView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
scrollView.widthAnchor.constraint(equalTo: view.safeAreaLayoutGuide.widthAnchor).isActive = true
scrollView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
contentView.centerXAnchor.constraint(equalTo: scrollView.centerXAnchor).isActive = true
contentView.widthAnchor.constraint(equalTo: scrollView.widthAnchor).isActive = true
contentView.topAnchor.constraint(equalTo: scrollView.topAnchor).isActive = true
contentView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor).isActive = true
当我向下滚动时,我的导航栏会变小:
然后我单击 tableviewcell,导航到 detailVC 并返回。这就是问题所在。不知何故,我的导航栏变大了,直到我向任何方向滚动它,然后它跳到正常状态。为什么会发生这种情况,可能是什么原因?
Here 是我的 ViewController 代码的要点
谢谢!
【问题讨论】:
【参考方案1】:我配置了我的约束并修复了这个问题。
新约束:
scrollView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
scrollView.widthAnchor.constraint(equalTo: view.safeAreaLayoutGuide.widthAnchor).isActive = true
scrollView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
contentView.topAnchor.constraint(equalTo: scrollView.topAnchor).isActive = true
contentView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor).isActive = true
contentView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor).isActive = true
contentView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor).isActive = true
// contentView.heightAnchor.constraint(equalTo: scrollView.heightAnchor).isActive = would be true if horizontal
contentView.widthAnchor.constraint(equalTo: scrollView.widthAnchor).isActive = true
【讨论】:
以上是关于返回导航到根视图控制器后,折叠的大标题导航栏变得展开的主要内容,如果未能解决你的问题,请参考以下文章