IOS 11 search bar has no top fill when status bar is hidden

When setting the status bar to hidden

override var prefersStatusBarHidden: Bool {
    return true
}

and initialize normal searchControllerusing

let searchController = UISearchController(searchResultsController: nil)
navigationItem.searchController = searchController

It looks normal if it is unedited, however, if you click on the search bar, the navigation title will be hidden, and there will be a small indentation between the search bar and the top edge, which is very visually violated.

The solution is appreciated.

Minimal example

https://github.com/DJBen/SearchBarNoTopPadding

enter image description here

+4
source share
1 answer

This is a bug in iOS 11. To get around this, add these lines to your code:

    searchController.hidesNavigationBarDuringPresentation = false
    self.definesPresentationContext = true

, . titleView. iOS 11.

+3

Source: https://habr.com/ru/post/1686166/


All Articles