iosuikituisearchcontroller

How to fix jump when click on search bar?


There is a phenomenon that jumps when you click the search bar.

The view is below.

https://i.sstatic.net/jFkgS.gif


my code.

lazy var searchController: UISearchController = {
    let searchController = UISearchController(searchResultsController: nil)
    searchController.searchBar.placeholder = "Search"
    searchController.hidesNavigationBarDuringPresentation = false
    searchController.searchResultsUpdater = self
    searchController.searchBar.delegate = self
    return searchController
}()

func setUpNavigationItem() {
    navigationItem.title = "Search"
    navigationItem.searchController = searchController
    navigationItem.hidesSearchBarWhenScrolling = true

    let loginButton = UIBarButtonItem(title: "Login", style: .plain, target: nil, action: nil)
    loginButton.tintColor = .label
    navigationItem.rightBarButtonItem = loginButton
}

Do you know how to solve it? Please help me.


Solution

  • https://developer.apple.com/documentation/uikit/uiviewcontroller/1621515-edgesforextendedlayout

    I have set "under top bars" of "extend edge" options in ViewController to "false".

    https://i.sstatic.net/pRO1W.png

    It was solved this way!