如何修复在iOS 12.1中点击内部时UISearchController的搜索栏向下移动?

时间:2019-05-22 12:39:47

标签: uisearchcontroller uinavigationitem ios12 titleview

我的应用包含一个standalone UINavigationBar,带有“左按钮项”和“右按钮项”。根据我们的要求,导航栏中的左/右按钮之间需要一个搜索栏。我已经将UISearchController的搜索栏设置为UINavigationItem的TitleView,如下所示

self.navigationItem.TitleView = self.searchController.SearchBar

对于低于12.0的iOS版本,搜索栏可以很好地放置在导航栏中的后退/前进按钮之间,并且可以毫无问题地接受击键。

对于iOS 12+版本,在搜索栏中点按时,搜索栏会向下移动。我尝试了以下代码行,但没有用。任何有关解决方案的建议都会有所帮助。

[self.searchController.searchBar sizeToFit];
self.searchController.hidesNavigationBarDuringPresentation = NO;

[self.navigationBar setPrefersLargeTitles:YES];
[self.navigationItem setLargeTitleDisplayMode:UINavigationItemLargeTitleDisplayModeAlways];

self.definesPresentationContext = YES;
self.extendedLayoutIncludesOpaqueBars = YES;

0 个答案:

没有答案
相关问题