问题很简单,当滚动视图向下滚动时,我如何防止大标题导航栏折叠?
我的导航栏必须始终有一个大的导航栏...所以当滚动视图滚动时,导航栏不应该折叠起来,它应该保持相同的大小,我该怎么做?
这是我设置大标题偏好的方式
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationItem.hidesBackButton = true
presenter.expandForSimulatorLayoutIfNeeded()
}
func expandForSimulatorLayoutIfNeeded(){
if !isExpanded{
topMenu = TopMenu(frame: expandedNavigationFrame, interactor: interactor)
oldNavigationBarFrame = navigationBar.frame
self.navigationBar.addSubview(topMenu)
}
if #available(iOS 11.0, *) {
self.navigationBar.prefersLargeTitles = true
} else {
self.navigationBar.frame = expandedNavigationFrame
}
let topConstraint = NSLayoutConstraint(item: topMenu, attribute: .top, relatedBy: .equal, toItem: navigationBar, attribute: .top, multiplier: 1, constant: 0)
let leadingConstraint = NSLayoutConstraint(item: topMenu, attribute: .leading, relatedBy: .equal, toItem: navigationBar, attribute: .leading, multiplier: 1, constant: 0)
let widthConstraint = NSLayoutConstraint(item: topMenu, attribute: .width, relatedBy: .equal, toItem: self.navigationBar, attribute: .width, multiplier: 1, constant: 0)
let bottomConstraint = NSLayoutConstraint(item: topMenu, attribute: .bottom, relatedBy: .equal, toItem: navigationBar, attribute: .bottom, multiplier: 1, constant: 0)
topMenu.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([leadingConstraint, widthConstraint, topConstraint, bottomConstraint])
}
VStack(spacing; 0)
来使内容尽可能接近PreventCollapseView
。 - Jeremy