The Apple guy in the What\'s new in Cocoa Touch WWDC video said that the new large-title navigation bar will magically hook into the top-level scroll view of the underlying
Year 2020, iOS 13.0, this WAS NEVER mentioned here. I literally spent an hour or two for this.
Issue: Large title won't collapse when doing layout programmatically using Snapkit (an autolayout framework)
Solution: SETUP YOUR VIEWS (including navigationController stuff and tableView) inside loadView()
NOT in viewDidLoad()
.
Since I can't comment I'll share here the answer I posted
https://stackoverflow.com/a/47493375/8385022
I found a workaround on this site basically, if the tableView (or element that has scroll)is not the first view in your view hierarchy, the large title fails to hide automatically.
Example that will NOT work Example that will work
https://markusbodner.com/2017/10/08/fix-large-navigation-bar-title-not-hiding-on-scroll-in-ios-11/
I added on the view willAppear:
if #available(iOS 11.0, *) {
navigationController?.navigationBar.prefersLargeTitles = true
} else {
// Fallback on earlier versions
}
If there is any other view in addition to tableView, also make sure tableView is on the top of that view(s), right under the Safe Area:
Make sure that addSubview(tableView)
placed before others addSuview(someview)
@TamasZahola @mohamede1945
Guys I had the same problem. I was able to resolve this issue by adding following snippet on my first View Controller of Navigation Controller
navigationController?.navigationBar.prefersLargeTitles = true
Good news! I've just figured out that if I set "Large Titles" to "Never" on the storyboard, and then set it via code, then it works:
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeAutomatic;
}
Seems like Apple forgot to handle the case when the navigation item has its largeTitleDisplayMode
set via the Interface Builder.
So until they fix this issue, leave "Large Titles" as "Never" on storyboards, and set them via code in viewDidLoad
.
You just need to do that to the first view controller. Subsequent view controllers honor the value in storyboard.