Mickael Belhassen
Mickael Belhassen

Reputation: 3352

Swift: UISearchController bug content behind navigation bar after pushing view controller

There is a very weird bug when I push a control to navigation controller and when I return back, look at the gif below.

Before push the detail view controller enter image description here

After click on back button from detail view controller enter image description here

My code:

searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.placeholder = Localizations.searching
searchController.hidesNavigationBarDuringPresentation = false
searchController.searchBar.showsScopeBar = true

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

Upvotes: 0

Views: 378

Answers (2)

xapslock
xapslock

Reputation: 1129

Had the same Problem and found a feasible solution:

After you add the TableView to your ViewController, pinn all directions to the safeAreaLayout(or superview)

self.view.addSubview(tableView)
tableView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 0).isActive = true
tableView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 0).isActive = true
tableView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: 0).isActive = true
tableView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: 0).isActive = true

And activate Extend Edges - Unter Opaque Bars

enter image description here

Upvotes: 0

Mickael Belhassen
Mickael Belhassen

Reputation: 3352

For the moment I have found a solution but that looks bad.

After push the viewcontroller I must run this:

        let searchedText = searchController.searchBar.text
        searchController.isActive = false
        searchController.searchBar.text = searchedText

Upvotes: 1

Related Questions