Can't enable prefersLargeTitles for UIViewController

So maybe I'm overlooking something, but for two ViewControllers that subclass UIViewController, the prefersLargeTitles behaviour does not work as expected.


When the VC is loaded, the navigation bar is the regular small size, and only after I manually scroll up it will become larger.


For another VC I'm using a UITableViewController and there, everything works fine.


This is my code:


if #available(iOS 11.0, *) {
            self.navigationController?.navigationBar.prefersLargeTitles = true
            self.navigationItem.largeTitleDisplayMode = .always
            self.navigationController?.navigationBar.isTranslucent = false
        } else {
            /
        }


Any help would be greatly appreciated!

Was caused by UIEdgeInsets, nevermind 🙂

Create a base navigation class:

Code Block
class BaseNavigationController: UINavigationController {
  override func viewDidLoad() {
    super.viewDidLoad()
   navigationBar.prefersLargeTitles = true
  }
}



Create a new VC class and set largeTitleDisplayMode to .always, never or automatic:
Code Block
final class TableViewController: UITableViewController {
  
 override func viewDidLoad() {
  super.viewDidLoad()
  navigationItem.largeTitleDisplayMode = .always
 }
}


Very sad that Apple has this issue.
Tested on iOS 14.4
Can't enable prefersLargeTitles for UIViewController
 
 
Q