在具有搜索控制器搜索栏的视图控制器之间隐藏和显示具有ui故障的导航

时间:2019-03-15 14:48:19

标签: ios swift uisearchbar uisearchcontroller

我在UISearchController中使用了简单的UITableViewController。当我在第一个控制器中使用搜索栏时出现问题,该搜索栏在下一个或后面隐藏时显示UI故障。

这是它的外观>> enter image description here

以下是用于设置导航栏的代码。

self.extendedLayoutIncludesOpaqueBars = true

let navigationBar = navigationController.navigationBar
let navigationBarTitleTextAttritbutes = [NSAttributedString.Key.foregroundColor: UIColor.white]
navigationBar.titleTextAttributes = navigationBarTitleTextAttritbutes

if #available(iOS 11.0, *) {
    navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
    navigationBar.prefersLargeTitles = false
}
navigationBar.isTranslucent = false
navigationBar.tintColor = UIColor.white
navigationBar.barTintColor = UIColor.purple

并且用于设置如下所示的搜索控制器

self.searchController = UISearchController(searchResultsController: nil)
self.searchController.dimsBackgroundDuringPresentation = false
self.searchController.hidesNavigationBarDuringPresentation = false
self.searchController.hidesBottomBarWhenPushed = true
self.searchController.obscuresBackgroundDuringPresentation = false

let searchBarObj = self.searchController.searchBar
searchBarObj.delegate = self as? UISearchBarDelegate
searchBarObj.placeholder = "Search here"
searchBarObj.isTranslucent = false
searchBarObj.tintColor = .white

if #available(iOS 11.0, *) {

    searchBarObj.tintColor = .white
    searchBarObj.barTintColor = .white
    navigationItem.searchController = searchController
    navigationItem.hidesSearchBarWhenScrolling = true
} else {
    let tintColor = UIColor.purple
    searchBarObj.barTintColor = tintColor
    searchBarObj.layer.borderColor = tintColor.cgColor
    searchBarObj.layer.borderWidth = 1
    if let table = tableview {
        table.tableHeaderView = searchController.searchBar
    }
}

0 个答案:

没有答案