UISearchController searchBar in tableHeaderView animating out of the screen

前端 未结 8 1414
南方客
南方客 2020-12-25 11:13

I have a UISearchController with a UITableViewController as a searchResultsController, the UISearchBar of this sear

相关标签:
8条回答
  • 2020-12-25 11:43

    Have you tried to set the hidesNavigationBarDuringPresentation to false? Solved my headache..

    self.searchController.hidesNavigationBarDuringPresentation = false;
    

    Putting the searchbar in the navigation bar gives a more solid user experience in my opinion (for iphone)

    self.navigationItem.titleView = self.searchController.searchBar;
    
    0 讨论(0)
  • 2020-12-25 11:57

    SWIFT 3.01

    func willPresentSearchController(searchController: UISearchController){
    self.navigationController?.navigationBar.isTranslucent = true
    }
    
    func willDismissSearchController(searchController: UISearchController) {
    self.navigationController?.navigationBar.isTranslucent = false
    }
    
    0 讨论(0)
  • 2020-12-25 11:59

    Try this out:

    First you need to delegate the

    UISearchControllerDelegate

    For Swift

    func willPresentSearchController(searchController: UISearchController) {
        self.navigationController?.navigationBar.translucent = true
    }
    
    func willDismissSearchController(searchController: UISearchController) {
        self.navigationController?.navigationBar.translucent = false
    }
    
    0 讨论(0)
  • 2020-12-25 12:02

    To make this clearer @Lorenzo's answer worked for me.

    self.definesPresentationContext = YES;
    
    0 讨论(0)
  • 2020-12-25 12:02

    In Swift, try:

    override func viewDidLoad() {
        edgesForExtendedLayout = []
        searchController.hidesNavigationBarDuringPresentation = false
    
        // ...
    }
    
    0 讨论(0)
  • 2020-12-25 12:03

    In my case the searchBar was in the tableHeaderView and there was no NavigationBar on screen. But the SearchBar still animated upwards overlapping the status bar when becoming active. The solution to prevent this was to set:

    searchController.hidesNavigationBarDuringPresentation = false
    

    Which is weird because as I said the view controller was not using a navigation bar.

    0 讨论(0)
提交回复
热议问题