Search code examples
swiftios11uisearchcontrollerinteractivepopgesture

Search bar disappears when interactive pop gesture is happening


I'm adding search controller like this:

        viewController.navigationItem.searchController = searchController
        viewController.navigationItem.hidesSearchBarWhenScrolling = false
        viewController.definesPresentationContext = true
        searchController.dimsBackgroundDuringPresentation = false

        searchBarContainer.translatesAutoresizingMaskIntoConstraints = false
        searchBarContainer.heightAnchor.constraint(equalToConstant: 0).isActive = true

and when try to swipe right to pop current viewController (interactive pop gesture activates here) but stay on the same controller the search bar just disappears.

viewController.navigationItem.searchController

holds added search controller but it's not visible.


Solution

  • Try to add this code to whatever class viewController is an instance of:

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        self.definesPresentationContext = true
    }
    

    That did the trick for me.