The question is simple, how can I prevent a Large Title Navigation Bar from collapse when a scrollview scrolls down?
My navigation must have a large navigation bar at all times... so when a scrollview scroll, the navigation bar shouldn't collapse up, it should stay the same size, how can I do that?
This is how I set the largeTitle preferences
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)
to get the content as close to thePreventCollapseView
as possible. – Jealousy