UISearchBar没有向上移动 [英] UISearchBar Not shifting up

查看:178
本文介绍了UISearchBar没有向上移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知怎的,我不知道为什么默认动画会失败。

Somehow i dun know why does the default animation fails.

我的搜索栏没有按原样向上移动。

my Search bar did not shift up as it supposed to be.

视图在UIView中,我想知道这是否是问题。

the view is in UIView, i'm wondering if this is the problem.

包含IB布局



推荐答案

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

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
                 }];
}

这篇关于UISearchBar没有向上移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆