I am facing an issue on the UISearchController when the device is rotated on iOS 13.
I have a tableView and this tableView has a searchBar as header. This was working properly until the iOS 13 release, now there is an unwanted behaviour on rotate device.
If the device is on portrait orientation and the searchBar is in focus then I rotate the device to landscape orientation the searchBar is not at the correct position; As you can see on the image bellow the search bar must be into the yellow view, but it is a little bit bellow it
but when the cancel button is pressed the search bar goes to the correct position.
I already debug it and the view seems to be created at the correct place, including the frame size and origin.
A similar behaviour happens when the focus is on the search bar and the orientation is in landscape then it is changed to portrait.
my code to add the search bar:
func setupSearchBar() {
searchController.searchResultsUpdater = self
searchController.hidesNavigationBarDuringPresentation = false
searchController.delegate = self
searchController.definesPresentationContext = true
searchController.searchBar.returnKeyType = UIReturnKeyType.done
searchController.searchBar.placeholder = "search here ..."
searchController.searchBar.tintColor = UIColor.red
searchController.searchBar.delegate = self
let yellowView: UIView = UIView.init(frame: searchController.searchBar.frame)
yellowView.backgroundColor = UIColor.yellow
yellowView.addSubview(searchController.searchBar)
tableView.tableHeaderView = yellowView
tableView.reloadData()
}
hidesSearchBarWhenScrolling
property of UINavigationItem is for. Again, look at the documentation for UISearchController. This is all shown as an example. – rmaddy