In landscape orientation UISearchController getting UI glitch issue. Using Xcode 10.2. There is not built-in navigationBar used.
Landscape Preview
Portrait Preview
Instance declaration
let searchController = UISearchController(searchResultsController: nil)
@IBOutlet weak var vwSearch: UIView!
@IBOutlet weak var vwSearchHeightConstant: NSLayoutConstraint!
Initialization in viewDidload
func setupSerachResultController()
{
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = true
searchController.searchBar.placeholder = "Search Email"
searchController.searchBar.searchBarStyle = .minimal
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.scopeBarBackgroundImage = UIImage.imageWithColor(color: UIColor.clear)
searchController.searchBar.tintColor = UIColor.white
vwSearch.addSubview(searchController.searchBar)
searchController.searchBar.scopeButtonTitles = ["One","Two","Three","Four"]
searchController.searchBar.delegate = self
}
Initial Preview
UISearchBarDelegate methods
extension ListViewController: UISearchBarDelegate,UISearchResultsUpdating {
func searchBar(_ searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int) {
}
func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool {
UIView.animate(withDuration: 0.3) {
self.vwSearchHeightConstant.constant = 100
self.view.layoutIfNeeded()
}
return true
}
func updateSearchResults(for searchController: UISearchController) {
let searchBar = searchController.searchBar
let scope = searchBar.scopeButtonTitles![searchBar.selectedScopeButtonIndex]
}
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
UIView.animate(withDuration: 0.3) {
self.vwSearchHeightConstant.constant = 60
self.view.layoutIfNeeded()
}
}
}
As shown in initial preview there is not scope bar visible so height of
vwSearch60, which managed usingvwSearchHeightConstantconstraint. For scope bar height changed to 100, which toggle managed insearchBarShouldBeginEditingandsearchBarCancelButtonClicked.
Any help much appreciated. Thank you.


