3
votes
func configureSearchController() {
    // Initialize and perform a minimum configuration to the search controller.
    searchController = UISearchController(searchResultsController: nil)
    searchController.searchResultsUpdater = self
    searchController.dimsBackgroundDuringPresentation = false
    searchController.searchBar.placeholder = "Search"
    searchController.searchBar.delegate = self
    searchController.searchBar.sizeToFit()

    // Add search bar to View.
    self.view.addSubview(searchController.searchBar)

    searchController.searchBar.translatesAutoresizingMaskIntoConstraints = false

    view.bringSubview(toFront: searchController.searchBar)

    //add constraints on searchbar
    view.addConstraint(NSLayoutConstraint(item: searchController.searchBar, attribute: .trailing, relatedBy: .equal, toItem: view, attribute: .trailing, multiplier: 1, constant: 0))
    view.addConstraint(NSLayoutConstraint(item: searchController.searchBar, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leading, multiplier: 1, constant: 0))

    view.addConstraint(NSLayoutConstraint(item: searchController.searchBar, attribute: .top, relatedBy: .equal, toItem: self.topLayoutGuide, attribute: .bottom, multiplier: 1, constant: 0))
    view.addConstraint(NSLayoutConstraint(item: searchController.searchBar, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute,multiplier: 1, constant: 64))

}

So that was my code, I added a searchController searchbar as subview to a View. I added constraints as well.

Whenever I type something in the search bar, the whole thing disappears, and also the navigation bar in an animated fashion.

First it looks like this So it looks like this

Then when I start typing, it's gone Poof It's gone

2
Its a Default behaviour for UISearchController, Can u Please attach screenshot.Piyush Sanepara
try playing with this settings self.extendedLayoutIncludesOpaqueBars = true or self.automaticallyAdjustsScrollViewInsets = trueConstantin Saulenco
It doesn't workChris Mikkelsen

2 Answers

0
votes

searchController1.hidesNavigationBarDuringPresentation = false

0
votes

Add the following to your ViewController

    definesPresentationContext = true