Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 11 prefersLargeTitles not expanding after orientation change

I've implemented the iOS 11 feature prefersLargeTitles and it works just fine. Portrait mode is working as expected:

enter image description here

I understand the large title will always stay collapsed (small) in landscape mode and that's fine to me. The problem is when I try to change to landscape and then again to portrait, the large title should be expanded (big) by default back in portrait mode, but it won't until I scroll down a bit:

enter image description here

My code looks quite simple:

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

I also tried using different values on tableView.contentInsetAdjustmentBehavior, nothing changed. I'm kind of solving it by now scrolling down the table programmatically after orientation changes, but I think that's just a (not very nice) workaround.

Is that supposed to be working as expected? Is it something left in my implementation? Is there a better workaround to this?

like image 665
juliancadi Avatar asked Aug 24 '18 11:08

juliancadi


Video Answer


1 Answers

I faced the same issue. This worked for me.

    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        navigationItem.largeTitleDisplayMode = .always
        coordinator.animate(alongsideTransition: { (_) in
            self.coordinator?.navigationController.navigationBar.sizeToFit()
        }, completion: nil)
    }
like image 191
Umar Avatar answered Nov 15 '22 09:11

Umar