0

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

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

知道怎么做吗?提前致谢

4

3 回答 3

1

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

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

[UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
       //Move it down here by changing its .frame
    }completion:^(BOOL finished){
    }];
于 2013-03-29T15:41:27.333 回答
1

您只需在单击搜索图标时更改 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 的工作 调用 Set The Frame of Searchbar with ANimation

 - (void)hideSearchBar{
 [UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

  thisSearchBar.frame = CGRectMake(0.0, -50, searchBarWidth, searchBarHeight)];

  }completion:^(BOOL finished)
  {
  }];

  }
于 2013-03-29T15:56:03.077 回答
0

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

searchBar.hidden = true;
于 2013-03-29T15:57:53.700 回答