iOS 13 strange search controller gap iOS 13 strange search controller gap swift swift

iOS 13 strange search controller gap


Setting

extendedLayoutIncludesOpaqueBars = true

in the UIViewController used to show the search results, fixed the issue for me.


We had the same issue and the solution was to set Under Opaque Bars (since we use opaque bars) Under Opaque Bars

We already had Top and Bottom checked, adding the third moved the search results controller to the correct location.


For me the problem was that UISearchController didn't update it's frame when search bar moved upwards. I fixed it by setting frame of UISearchController to the frame of it's presenting view controller.

extension UISearchController {    open override func viewWillAppear(_ animated: Bool) {        super.viewWillAppear(animated)        if let presentingVC = self.presentingViewController {            DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {                self.view.frame = presentingVC.view.frame            }        }    }}

In viewWillAppear animation of search bar did not start so you have to wait for a split second. When animation starts, frame of presenting VC is set to the correct value and then you can update frame of your UISearchController. The solution is a hack but it works fine for me.