Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIViewController with UITableView and UISearchBar gap issue

I have a UIViewController with a UITableView and a UISearchBar inside. As soon as the searchbar becomes first responder, there's a small gap between the searchbar and the tableview.

Initial stateSearchbar becomes first responder

There's no gap when the UISearchBar is a subview of the UIViewController view instead of being a subview of the UITableView.

Initial stateSearchbar becomes first responder

Obviously, one issue with that approach is that the searchbar stick to the top and doesn't scroll along with other cells, which is not desired.

Any ideas?

Edit:

Two first images correspond to the UISearchBar being a child of the UITableView, where the gap is occurring.

Last two images correspond to the UISearchBar being a child of the UIViewController view, in which case there's no gap.

like image 828
plgrenier Avatar asked Mar 18 '23 01:03

plgrenier


1 Answers

The gap is occurring when setting UINavigationBar translucent property to NO. Setting it to YES resolve the issue. Animation is smooth again and there's no gap between UISearchBar and UITableView. I can't explain why, and it appears to be a bug on Apple side as it is easy to reproduce by creating a sample project.

like image 95
plgrenier Avatar answered Apr 09 '23 11:04

plgrenier