用SearchController在View Bar下显示黑色矩形的ViewController推送视图

时间:2018-07-13 10:59:14

标签: swift uinavigationcontroller uisearchbar uisearchcontroller

当我将另一个控制器推入堆栈时(使用搜索控制器时),搜索栏下方出现一个黑色方块。在以下所有内容中,我都将背景色设置为白色;

  • 搜索控制器
  • 搜索栏
  • 当前VC
  • 下一个VC

当它回到堆栈中时也会出现。

搜索控制器

func setUpSearchController() {
        searchController.delegate = self
        searchController.view.backgroundColor = .white
        searchController.searchBar.backgroundColor = .white
        searchController = UISearchController(searchResultsController: nil)
        searchController.hidesNavigationBarDuringPresentation = true
        searchController.dimsBackgroundDuringPresentation = true
        searchController.searchBar.sizeToFit()
        searchController.searchBar.backgroundColor = .white
        searchController.searchBar.barTintColor = .white
        searchController.searchBar.placeholder = "Search"
        searchController.searchBar.searchBarStyle = .minimal
        searchController.searchBar.tintColor = Colours.brandGreen
        definesPresentationContext = true
        if #available(iOS 11.0, *) {
            navigationItem.searchController = searchController
            navigationItem.hidesSearchBarWhenScrolling = true
        } else {
            messagesTableView.tableHeaderView = searchController.searchBar
        }
    }

已选择单元格

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let chatController = ChatController()
        let message = messages[indexPath.row]
        chatController.title = message
        self.navigationController?.pushViewController(chatController, animated: true)
    }

illustration

一如既往,任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:5)

在这里找到答案: https://blog.kulman.sk/fixing-black-artifact-changing-large-tiles-mode/

代码

guard let navigationController = navigationController else { return }
navigationController.view.backgroundColor = .white

如上面的链接所述,此设置无法全局设置,因此需要在我要使用的每个NC上。