Reputation: 5001
Somehow i dun know why does the default animation fails.
my Search bar did not shift up as it supposed to be.
the view is in UIView, i'm wondering if this is the problem.
Included the IB layout
Upvotes: 6
Views: 5605
Reputation: 4180
The best way to implement an UISearchBar
and an UISearchDisplayController
following Apple guidelines is looking at the example called TableSearch, the description says:
Demonstrates how to search the contents of a UITableView using UISearchBar and UISearchDisplayController, effectively filtering in and out the contents of that table. If an iPhone/iPod Touch application has large amounts of table data, this sample shows how to filter it down to a manageable amount if memory usage is a concern or you just want users to scroll through less table content.
I hope this helps you.
Upvotes: 2
Reputation: 10296
In the first image of your question, you are showing a UISearchDisplayController being used. In order to achieve that exact animation, you will need to use a UISearchDisplayController and modify it's UISearchBar to look like the custom one you made. You can drag a UISearchDisplayController over in Interface Builder and then use code to change it's searchBar property.
self.searchDisplayController.searchbar
will be what you modify if you have everything hooked up correctly in Interface BUilder.
Upvotes: 1
Reputation: 3191
The searchbar doesn't actually move in the 'push-up' animation. Rather it stays in place while the navbar goes up, thus pulling the rest of the view with it. You should be able to move the search bar manually in code by registering as its delegate (UISearchBarDelegate) and responding to these calls.
#pragma mark - UISearchBarDelegate Methods
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
//move the search bar up to the correct location eg
[UIView animateWithDuration:.4
animations:^{
searchBar.frame = CGRectMake(searchBar.frame.origin.x,
0,
searchBar.frame.size.width,
searchBar.frame.size.height);
}
completion:^(BOOL finished){
//whatever else you may need to do
}];
}
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar {
//move the search bar down to the correct location eg
[UIView animateWithDuration:.4
animations:^{
searchBar.frame = CGRectMake(searchBar.frame.origin.x,
/*SearchBar original Y*/,
searchBar.frame.size.width,
searchBar.frame.size.height);
}
completion:^(BOOL finished){
//whatever else you may need to do
}];
}
Upvotes: 11