0
votes

I am trying to implement the UISearchController in my current project and I am struggling to correctly position its UISearchBar on my ViewController.

On my ViewController, I have a UIView that is used as a container view for the searchControllers searchBar. When the searchController is created, I add its searchBar as a subView of the ViewControllers container view. The ViewController is also embedded in a NavigationController, whose Navbars color is red.

The issue that I am having is when I active the search controller, by focusing on the searchBar, after the animation occurs the pushes the Navbar off of the screen, and fixes the searchBar to where the navBar once was, the background of the searchBar doesn't extend to cover the status bar.

enter image description here

The dark gray strip at the top of the View Controllers view is a mixture of the dimming view that comes with UISearchController and the white background where the red navigation bar once was.

Please let me know if you have any insight on this issue, or if you need more information.

1

1 Answers

0
votes

If you embedded your viewController in a UINavigationBarCOntroller or UITabBarViewControoler, the content is shown under status bar by default. I think you should fix the SearchBar to the edge of UIView after push off the navibar, not where the navBar once was.

However, this may still doesn't work for you. Then You need to add a constant to the top Anchor, to make the SearchBar extend a little to cover the status Bar. I had a try in my StoryBoard and it worked, I believe it's not hard to achieve it programmatically if you want.

Here I make a screenshot of how I set up the constraint of SearchBar, Top Space to: Top Layout Equals -20, the constant is important:

enter image description here

enter image description here

enter image description here