I'm implementing a location based keyword search. If anyone has seen Yelp's search bar, it is what i'm trying to do. Basically once the search bar is clicked i want to provide one text field input for the keyword and the other for location. What UI element would I subclass? How would I go about this?
Yelp's implementation looks to be a custom view with two UITextField objects, with a translation and scale animation to make it appear to be zoomed in from the top. A table view is added to the hierarchy after the animation is finished. The keyboard is invoked by making one of the text fields first responder.
BTW - generally speaking, composing UI elements together is preferred to subclassing.
I also did a similar app, quite a while ago.
What I did in my app was I followed these steps, (I am only giving a brief description not the code part):
Initial look:
viewDidLoad
of my class).UITextFields
one below the other. I made this view hidden and shifted its y coordinates by the height of the view so that they became -(viewHeight)
.Functionality Part
As soon as the user touches the search bar placed into the navigation bar, I made it hidden, unhidden the view with the text fields and shifted the y coordinates until they became 0 again.
In the delegate methods of search bar, - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
I returned NO, did the animation part (mentioned in the previous step) before returning NO from this method.
I made my first text field the first responder so that the keyboard appears automatically.
Now, when I am done filling data in both the text fields I reversed the animations and put the data filled into the text fields to the search bar.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With