导航栏Searchbar空间未隐藏在Swift 4.2中

时间:2019-02-16 11:46:47

标签: ios swift uinavigationbar uisearchbar

Navigationbar with SearchBar

enter image description here

嗨,我已经在Navigationbar和

中实现了Searchbar

以编程方式隐藏导航栏,但该空间并未删除 请帮助我如何删除搜索栏隐藏空间的空间

let search = UISearchController(searchResultsController: nil)


    search.searchResultsUpdater = self
    search.obscuresBackgroundDuringPresentation = false
    search.hidesNavigationBarDuringPresentation = false;
    search.searchBar.placeholder = "search..."
    self.definesPresentationContext = true
    self.navigationItem.searchController = search

用于隐藏SearchBar

search.searchBar.isHidden = false

1 个答案:

答案 0 :(得分:1)

隐藏它是不够的,因为它仍然是navigationItem searchController,因此您需要将其设置为nil

self.navigationItem.searchController = nil

,然后根据需要还原它,就这么简单。