surfrider
surfrider

Reputation: 1425

UISearchController's UISearchBar shifts incorrectly and jumps when UITableView is scrolled

In the video, it's a little difficult to see what's going on, so I'll try to explain it. https://youtu.be/yOrCJB9yZlg

I have UIViewController with UITableView inside its root view. Binded via Autolayout (there is no difference how it's binded: to SuperView or to SafeArea).

SearchBar added like this: let search = UISearchController(searchResultsController: nil) self.navigationItem.searchController = search

When I slowly scroll table, the transition between large navbar and compact navbar, and then animation of showing in and out of searchBar is too fast. Searchbar jumping in/out of navbar instead of smoothly opened/closed; navbar transitioning is jumping between two states, large and compact, without smoothly passes through the middle half-opened state while you slowly moving your finger on screen, like in system apps (Mail, Phone, Messages, Contacts etc).

I made the example from an empty project to demonstrate the issue; there isn't any changes to navigation bar logic, or any logic at all. Just two new VC's and this odd behaviour.

If i create xCode's "Master-Details" project example and add UISearchController to it, it will work properly. I assume its because they used UITableViewController instead of UIViewController + UITableView inside.

What the reason of this behaviour and how to fix it?

Upvotes: 3

Views: 1307

Answers (3)

ANURAG SHARMA
ANURAG SHARMA

Reputation: 21

I had the same problem with the search controller transition and tableview. like this its flickering or tableview was jumping. The search controller was on the navigation item.

The key solution is to remove safe area guide from your view controller and assign top bottom left right constraints to your tableview. It will be smooth like this

Upvotes: 2

fewlinesofcode
fewlinesofcode

Reputation: 3082

This is a known problem and your code seems fine. This problem was already discussed here.

Problem appears when you're using UIScrollView or its subclasses with large navigation titles. It doesn't work. Problem disappears when you use UICollectionViewController or UITableViewController instead.

Upvotes: 1

Manju Basha
Manju Basha

Reputation: 665

What you have done is correct. Did you try running your code in a device? Feels more like a glitch in the simulator. I tried what you tried and it works fine for me in the device. Whereas the glitch occurs in simulator.

Refer to this article. They have explained step by step process.

Upvotes: 1

Related Questions