I'm trying to use
prefersLargeTitles
UITableViewController
navigationController?.navigationBar.prefersLargeTitles = true
UIViewController
tableView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor).isActive = true
tableView.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
tableView.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
tableView.bottomAnchor.constraint(equalTo: self.otherView.topAnchor).isActive = true
tableView
UITableViewController
tableView
Seems that I have been able to emulate this behavior more or less closely enough. Implementing the delegate method for the tableView
that reacts to scrolling, and then running the code that uses current contentOffset
to either show, or hide the large title (UITableView
inherits from UIScrollView
, so the scrollView
parameter refers in this case to the tableView
):
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView.contentOffset.y <= 0 {
self.navigationItem.largeTitleDisplayMode = .always
} else {
self.navigationItem.largeTitleDisplayMode = .never
}
self.navigationController?.navigationBar.setNeedsLayout()
self.view.setNeedsLayout()
UIView.animate(withDuration: 0.25, animations: {
self.navigationController?.navigationBar.layoutIfNeeded()
self.view.layoutIfNeeded()
})
}