简体   繁体   中英

Navigationbar with searchbar will not show large title

I have a UISplitViewController with a UINavigationController as the masterviewcontroller. This UINavigationController has a UICollectionViewController as its rootViewController. In the UICollectionViewController , I have set the following parameters:

self.collectionView.scrollEnabled = YES;
self.collectionView.bounces = YES;
self.collectionView.alwaysBounceVertical = YES;
self.navigationController.navigationBar.prefersLargeTitles = YES;

UISearchController *sc = [[UISearchController alloc] initWithSearchResultsController:nil];
self.navigationItem.searchController = sc;

The UISearchBar does show up in the navigationBar, but when I launch the app the navbar is collapsed to the small title. It's only when I drag the view downwards that the large title and the search bar appear.

Where I expect the view to launch like this

在此处输入图片说明

it actually launches like this

在此处输入图片说明

Any ideas what could be causing this?

Make sure you set preferLargeTitles to true in your UINavigationBar; either in code or in the Storyboard file.

Put this in your viewDidLoad.

self.navigationController?.navigationBar.prefersLargeTitles = true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM