【问题标题】:xcode - make searchbar appear/disappearxcode - 使搜索栏出现/消失
【发布时间】:2013-03-29 15:38:28
【问题描述】:

我的 mapview 应用程序有一个用于搜索具体地址的搜索栏。 它现在可以正常工作,它以“静态”方式出现在地图上方。 我的想法是使用图片中的“搜索”按钮使其出现和消失:

你知道怎么做吗? 提前致谢

【问题讨论】:

  • 你有什么尝试吗? searchBar.hidden = true;?
  • 谢谢 woz,我只是试试你的建议。尽管我正在考虑动画(从/到顶部),但它仍然有效。

标签: iphone ios cocoa-touch searchbar


【解决方案1】:

您可以在代码中执行此操作。您所要做的就是改变它的框架。

将其添加到您的navigationBar.frame 及其下方,然后在点击图标时将其放下。我通常也使用此代码使其看起来不错:

[UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
       //Move it down here by changing its .frame
    }completion:^(BOOL finished){
    }];

【讨论】:

    【解决方案2】:

    您只需要在单击搜索图标时更改 UISearchBar 的框架即可显示它。 见

    最初,当你不显示 UISearchBar 时,你应该以这种方式设置 Frame。

    将UISearchBar的Frame设置在ViewFrame的外侧。

    thisSearchBar.frame = CGRectMake(0.0, -50.0, searchBarWidth, searchBarHeight)];viewDidLoad 方法中

    单击搜索图标以显示 UISearchBar

     - (void)showSearchBar{
     [UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
    
      thisSearchBar.frame = CGRectMake(0.0, 50, searchBarWidth, searchBarHeight)];
    
      }completion:^(BOOL finished)
      {
      }];
    

    }

    你又完成了 SearchBar 的工作,调用了用动画设置 Searchbar 的框架

     - (void)hideSearchBar{
     [UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
    
      thisSearchBar.frame = CGRectMake(0.0, -50, searchBarWidth, searchBarHeight)];
    
      }completion:^(BOOL finished)
      {
      }];
    
      }
    

    【讨论】:

    • 抱歉迟到了(我在度假)。您的解决方案似乎是我正在寻找的,但什么是“图像”(在 image.size.width 中使用)?
    【解决方案3】:

    根据我的评论,只需使用:

    searchBar.hidden = true;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多