简体   繁体   中英

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.imgur.com/reKZ1wA.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.

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.imgur.com/eVudSQO.png

It was solved this way!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM