I have an iOS 7 application in XCode 5.0 that exhibits some strange behavior when tapping the search bar (UISearchBar
).
My application has a Navigation Controller, and a Tab Bar Controller. Here is an example of what my Main.Storyboard looks like:
[Navigation Controller] -> [Tab Bar Controller] -> [Tab Item #1]
|
-------------> [Tab Item #2]
Each [] is a view controller
When I launch my application, I see the Tab Item 1
with the UISearchBar
as shown in the screenshot below:
When I tap the UISearchBar
, the search bar slides up to the top of the screen, but the Navigation Bar does not hide, and the view does not "slide up". This causes the app to look like this:
When I delete the Tab Bar Controller
from the storyboard and connect the Navigation Controller
directly to Tab Item #1
the Navigation Bar hides as expected.
How can I make the Navigation Bar hide when tapping the Search Bar? For an example of the functionality I am looking to reproduce, click the search bar under the "Contacts" tab of the default iOS7 "Phone" application.
Best Answer
For swift developers:
This will hide the navigation bar while search bar is active and show it again when search bar is inactive.