UISearchController landscape orientation layout issue

Viewed 214

In landscape orientation UISearchController getting UI glitch issue. Using Xcode 10.2. There is not built-in navigationBar used.

Landscape Preview

enter image description here

Portrait Preview

enter image description here

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

enter image description here

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 vwSearch 60, which managed using vwSearchHeightConstant constraint. For scope bar height changed to 100, which toggle managed in searchBarShouldBeginEditing and searchBarCancelButtonClicked.

Any help much appreciated. Thank you.

0 Answers
Related