Ios 如何阻止搜索栏隐藏在滚动条上

Ios 如何阻止搜索栏隐藏在滚动条上,ios,swift,Ios,Swift,我有一个UINavigationController,它将一个UISearchController分配给导航项的searchController。在视图中,我有一个UICollectionView。搜索栏显示在导航栏中,但当我滚动时,导航栏会自动隐藏。我能阻止这一切发生吗 let searchController = UISearchController(searchResultsController: recentSearchesViewController) searchController

我有一个
UINavigationController
,它将一个
UISearchController
分配给导航项的
searchController
。在视图中,我有一个
UICollectionView
。搜索栏显示在导航栏中,但当我滚动时,导航栏会自动隐藏。我能阻止这一切发生吗

let searchController = UISearchController(searchResultsController: recentSearchesViewController)
searchController.searchResultsUpdater = recentSearchesViewController
searchController.dimsBackgroundDuringPresentation = true
definesPresentationContext = true
navigationItem.searchController = searchController
您必须设置:

navigationItem.hidesSearchBarWhenScrolling = false
请查收