首页 > 解决方案 > 在视图控制器与搜索控制器搜索栏之间导航隐藏和显示有 ui 故障

问题描述

我用过简单UISearchControllerUITableViewController. 当我在第一个控制器中使用搜索栏并且隐藏在下一个或后退中时,这会出现问题,它会显示 UI 故障。

这是它的外观>> 在此处输入图像描述

下面是设置导航栏的代码。

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
    }
}

标签: iosswiftuisearchbaruisearchcontroller

解决方案


推荐阅读