I'm trying to use prefersLargeTitles
from iOS 11 in my application. It works as expected in subclasses of UITableViewController
:
navigationController?.navigationBar.prefersLargeTitles = true
However, in one case I needed to subclass UIViewController
and add a table view myself. In this situation I needed to constraint the table to the view myself:
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
While these constraints present the tableView
as I would expect, now the navigation bar always uses large title. I would like to mimic the behavior of the UITableViewController
, so that when the tableView
is scrolled to top, the large title is presented, otherwise the title collapses into the normal one.
How to solve this?
See Question&Answers more detail:os