[英]Search bar gets cut off when using UISearchController with a UITabBarController inside a UINavigationController
[英]UISearchBar gets cut off when using a UINavigationController inside a UITabBarController
我正在嘗試在我的UITabBarController中的一個選項卡中實現一個搜索欄,該選項卡是UINavigationController中的UITableViewController ...我正在關注Apple教程 - 我嘗試了很多不同的選項,包括這里提到的答案
在UINavigationController中使用帶有UITabBarController的UISearchController時,搜索欄會被切斷
我嘗試使用設置以下屬性
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
}
這是搜索欄的圖片:
好的,終於解決了這個問題。 這條線讓它發揮作用
self.extendedLayoutIncludesOpaqueBars = true
我的TabBar不是半透明的,所以我認為這不會有所作為,但我在我的UITableviewcontroller(顯示UISearchController的控制器)上設置了它,現在正確搜索導航欄中的顯示。 我還在頂部和底部欄下的擴展邊緣設置為true(使用Interface Builder)
雖然我的搜索欄在iOS 9中使用sizeToFit
上的sizeToFit以及托管搜索結果視圖控制器的視圖控制器上的definesPresentationContext=true
,但在iOS 10中已經發生了一些變化。
適用於我的新修復是禁用搜索結果視圖控制器上的調整滾動視圖插入。 我只是在Interface Builder中這樣做了。 我不得不啟用Extend Edges。 奇怪的是,這使得Interface Builder顯示在導航欄下被切斷的表格單元格,但它在運行時不會被切斷。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.