Reputation: 1024
I my mapview app, I have a search bar used to search a concrete address. It works bur for now, it appear in "static" way above the map. My idea is make that it appear and disapperar using a button "search" as in the picture:
Any idea about hoy do thath? Thanks in advance
Upvotes: 0
Views: 3669
Reputation: 6067
You just Need To change the Frame of UISearchBar as You click search Icon to display it. See
Initially,When You don't to display UISearchBar You should set the Frame In such manner.
initially set The Frame of UISearchBar Out Side The ViewFrame.
thisSearchBar.frame = CGRectMake(0.0, -50.0, searchBarWidth, searchBarHeight)];
in viewDidLoad
method
On clicking the Search Icon to display the UISearchBar
- (void)showSearchBar{
[UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
thisSearchBar.frame = CGRectMake(0.0, 50, searchBarWidth, searchBarHeight)];
}completion:^(BOOL finished)
{
}];
}
And You finished Work With SearchBar Again Call Set The Frame of Searchbar with ANimation
- (void)hideSearchBar{
[UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
thisSearchBar.frame = CGRectMake(0.0, -50, searchBarWidth, searchBarHeight)];
}completion:^(BOOL finished)
{
}];
}
Upvotes: 1
Reputation: 12051
You can do this in code. All you have to do is change its frame.
Add it to your navigationBar.frame
and below it and then, when the icon is tapped, put it down. I usually use this code to make it look nice too:
[UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
//Move it down here by changing its .frame
}completion:^(BOOL finished){
}];
Upvotes: 1