Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 11 prefersLargeTitles not updating until scroll

I implemented a basic UIViewController with a UITableView that's wrapped in a UINavigationController. I set prefersLargeTitles to true:

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    navigationController?.navigationBar.prefersLargeTitles = true
    navigationItem.title = "Coffees"
}

However, the title stays small until I scroll the view, at which point it enlarges. I tried moving that call to where I create the UINavigationController, but there was no effect. I am sure the navigationController is not nil when I set prefersLargeTitles.

Should I be updating that property elsewhere? Or should I file a Radar?

Update:

This only seems to happen if my view contains a UITableView or is itself a UITableViewController

like image 290
John Breen Avatar asked Jun 09 '17 02:06

John Breen


2 Answers

I recently hit the same issue and none of the suggestions worked for me. Instead, all I needed to do was to invoke sizeToFit(). Sample code:

private func configureNavigator() {
    guard let navigationController = navigationController else { return }
    navigationController.navigationBar.prefersLargeTitles = true
    navigationItem.largeTitleDisplayMode = .automatic
    navigationController.navigationBar.sizeToFit()
}

I hope this helps!

like image 123
titusmagnus Avatar answered Nov 16 '22 13:11

titusmagnus


For me the only working solution is:

DispatchQueue.main.async { [weak self] in
    self?.navigationController?.navigationBar.sizeToFit()
}

in

viewWillAppear()
like image 53
Trzy Gracje Avatar answered Nov 16 '22 13:11

Trzy Gracje