I'm transitioning from a view with a large style UINavigationItem
into a view that has a large style UINavigationItem
and a UISearchController
. I've customized the background colour of the UINavigationBar
.
For some reason, there's a 1px line or space between the UINavigationBar
and the UISearchController
. I can tell it's from the NavigationBar
, because if I scroll so that the search bar sticks to the top, the line disappears. I'm just not sure what's generating this line. I'm not using shadows, or anything fancy, other than setting the barTintColor
and the tintColor
. If I don't use large style titles, I see the line, but only when transitioning between views. It's like when transitioning the UISearchController
just doesn't stick right to the UINavigationBar
.
Any help in figuring out where this line is coming from is appreciated.
Update: On some further investigation, it seems this only happens when navigationItem.hidesSearchBarWhenScrolling
is set to false
. If it initially is hidden, then the animation from the previous view is smooth, and showing the bar is also smooth.
Testing the navigation item and search bar setup you've described, I could only reproduce the 1px/point line during the transition animations.
Workaround: This line is actually a background layout view (
forLastBaselineLayout
) used byUINavigationBar
ending up visible due to the buggy framing ofUISearchBar
. Set its background to match your navigation bar color to hide it in hind siteMake sure to set the object implementing
UINavigationControllerDelegate
is set asnavigationController.delegate
to receive the above delegate call.In addition (not part of the question):
UISearchBar
seems to behave strangely when transitioning (push and pop) between controllers especially when one has/show asearchBar
but not the other. Workaround, I found it visually more pleasing to temporarily hide the search bar from presenting controllers. Here is the code I use: