Search code examples
swiftuinavigationcontrolleruinavigationbar

Can large titles be maintain when the user scrolls within a navigation controller


I've set navigationController?.navigationBar.prefersLargeTitles = true and I'm wondering is there any option that prevents the default action of scrolling the title into the main Navigation bar when the user scrolls.

I can't see anything obvious within the nav bar properties but wanted to ask first before I build my own view that I will pin to the bottom of the nav bar.

Thanks


Solution

  • Ok, I've solved my issue with a simple workaround that works great. Instead of adding my UIScrollView to the UIViewController.view and constraining it to the view.topAnchor, I've added a UIView [named staticView] to my UIViewController. Constraining that staticView to the view.topAnchor and then constraining UIScrollView to my static view prevents the largeTitles from being reduced, while still allowing the user to scroll.

    When a UIScrollView is constrained to the topAnchor the OS reduces the nav bars large titles to their default size as the user scrolls. Having the scroll view pinned to the static view interrupts this behaviour and the large titles remain.