On iOS 11, where the search bar for is able/recommend to be attached to the navigation controller with navigationItem.searchController = searchController
, animating a contentOffset
change seems a little buggy, as the search bar seems to often stay in place. Immediately scrolling afterward fixes it, but it's ugly to see.
If you scroll all the way to the top by tapping the status bar (causing the search bar to be visible), and then animate a contentOffset
change on the UIScrollView
, you can see the search bar sticking around sometimes, specifically on device rather than simulator (but you can still see on simulator that the nav bar is too tall):
This can be observed very easily with even one of Xcode's template projects, such as "Master Detail", by adding a search controller and then adding a button to jump back up.
@objc func goBackUp(_ sender: Any) {
tableView.setContentOffset(CGPoint(x: 0.0, y: 1200), animated: true)
}
Here's an example project showing that: Sample Project
I'm aware this is most likely an iOS bug as there's no issue on iOS 10 and earlier, but does anyone know of a fix in the meantime?