在UITabBarController中使用UINavigationController时,UISearchBar会被截断

我试图在我的UITabBarController的选项卡之一实现一个search栏,该选项卡是UINavigationController内的UITableViewController …我遵循苹果教程 – 我已经尝试了很多不同的选项,包括这里提到的答案

在UINavigationController中使用带有UITabBarController的UISearchController时,search栏被切断

我已经尝试使用下面的属性设置

self.definesPresentationContext = true 

要么

 self.tabBarController?.definesPresentationContext = true 

这里是我的代码(从UITableViewController包含UISearchBar):

 /// Search controller to help us with filtering. var searchController: UISearchController! /// Secondary search results table view. var resultsTableController: SearchResultsTableController! override func viewDidLoad() { super.viewDidLoad() resultsTableController = SearchResultsTableController() resultsTableController.tableView.delegate = self searchController = UISearchController(searchResultsController: resultsTableController) searchController.searchResultsUpdater = self searchController.searchBar.sizeToFit() self.tableView.tableHeaderView = searchController.searchBar searchController.delegate = self searchController.dimsBackgroundDuringPresentation = true searchController.searchBar.delegate = self // so we can monitor text changes self.definesPresentationContext = true } 

以下是search栏的图片:

在这里输入图像说明

一旦我点击它: 在这里输入图像说明

好的,终于解决了这个问题。 这条线让它工作

 self.extendedLayoutIncludesOpaqueBars = true 

我的TabBar是不是半透明的,所以我不认为这将有所作为,但我在我的UITableviewcontroller(显示UISearchController的控制器)上设置,现在正确search显示在导航栏中。 我也有扩展边缘顶部和底部酒吧设置为true(使用界面生成器)

虽然我的search栏在iOS 9中使用sizeToFit的searchBar上的sizeToFit,以及承载search结果视图控制器的视图控制器上的definesPresentationContext=true ,但iOS 10中的内容已经发生了变化。

适用于我的新修补程序是禁用search结果视图控制器上的“调整滚动视图插入”。 我只是在Interface Builder中做了这个。 我不得不离开延长边缘启用。 奇怪的是,这使得界面生成器显示在导航栏下被切断的表格单元格,但是在运行时不会被截断。