简体   繁体   中英

Weired animation of tableview and searchbar of UISearchController embed in navigationbar

I've embed UISearchController into the navigationbar and my view controller has the table view. When I click on searchbar and keyboard appears tableview and searchbar does not animate smoothly. It seems like searchbar is overlaping navigationbar.

Here is the code,

Declare searchcontroller as a variable like,

var resultSearchController = UISearchController()

and defination in viewDidLoad is like,

self.resultSearchController = ({
        let controller = UISearchController(searchResultsController: nil)
        controller.searchResultsUpdater = self
        controller.obscuresBackgroundDuringPresentation = false;
        self.navigationItem.searchController = controller
        return controller
    })()

Animation issue is like below gif(watch till end to see slow animation)

在此处输入图像描述

I want same duration for animation for tableview, navigation bar, and searchbar.

Any help will be appreciated.

Don't set UITableView top anchor to be pinned to safeArea but to superview .

Important extra note to the accepted answer: If you use a UIViewController with subviews, including a UITableView , the UITableView has to be the first subview (ie: at index 0).

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