UISearchBar没有向上移动

Des*_*ond 6 iphone uisearchbar ios

不知何故,我知道为什么默认动画失败.

我的搜索栏没有按照预期的那样向上移动.

视图在UIView中,我想知道这是不是问题.

包括IB布局

在此输入图像描述 在此输入图像描述 在此输入图像描述

And*_*mer 11

搜索栏实际上并没有在"俯卧撑"动画中移动.而是在导航栏上升时保持原位,从而用它拉动视图的其余部分.您应该能够通过注册为其委托(UISearchBarDelegate)并响应这些调用,在代码中手动移动搜索栏.

#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
                 }];
}
Run Code Online (Sandbox Code Playgroud)