I set up a UISearchController
like this:
searchResultsController = SearchResultsController()
searchController = UISearchController(searchResultsController: searchResultsController)
searchController.searchResultsUpdater = self
searchController.hidesNavigationBarDuringPresentation = false
searchController.dimsBackgroundDuringPresentation = true
searchController.searchBar.searchBarStyle = .minimal
searchController.delegate = self
definesPresentationContext = true
navigationItem.titleView = searchController.searchBar
SearchResultsController
is just a view controller with UITableView
to show search results.
When the device is in portrait, start searching in portrait mode, there is an extra space on top of the table view (the RESULT header is the start of table view)
Then if I rotate to landscape mode, the space disappeared:
When device is in landscape mode and I start search, then the table view is cut off:
Then if I rotate to portrait, the table view fits perfectly:
The extra space height is exactly same as status bar height. So I wonder there is something related to the status bar here.
This didn't happen if I assign the searchbar as table view's tableHeaderView
. It only happens when searchbar is in navigation title. Anyone know why?
ApparentlyautomaticallyAdjustsScrollViewInsets
is getting deprecated.
'automaticallyAdjustsScrollViewInsets' was deprecated in iOS 11.0: Use UIScrollView's contentInsetAdjustmentBehavior instead
So I would suggest doing something like:
searchResultsController.tableView.contentInsetAdjustmentBehavior = .never
It worked like a charm for me. Some useful documentation:
contentInsetAdjustmentBehavior
UIScrollViewContentInsetAdjustmentBehavior
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With