Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISearchBar Not shifting up

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

enter image description hereenter image description hereenter image description here

like image 297
Desmond Avatar asked Nov 04 '11 10:11

Desmond


1 Answers

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
                 }];
}
like image 164
Andrew Zimmer Avatar answered Oct 22 '22 08:10

Andrew Zimmer