我的 mapview 应用程序,我有一个用于搜索具体地址的搜索栏。它现在可以正常工作,它以“静态”方式出现在地图上方。我的想法是使用图片中的“搜索”按钮使其出现和消失:
知道怎么做吗?提前致谢
我的 mapview 应用程序,我有一个用于搜索具体地址的搜索栏。它现在可以正常工作,它以“静态”方式出现在地图上方。我的想法是使用图片中的“搜索”按钮使其出现和消失:
知道怎么做吗?提前致谢
您可以在代码中执行此操作。你所要做的就是改变它的框架。
将其添加到您的navigationBar.frame
和下方,然后在点击图标时将其放下。我通常使用此代码使其看起来也不错:
[UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
//Move it down here by changing its .frame
}completion:^(BOOL finished){
}];
您只需在单击搜索图标时更改 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)
{
}];
}
根据我的评论,只需使用:
searchBar.hidden = true;