如何用动画隐藏/显示 UISearchBar 的范围栏?
我想在表格为空时(在搜索栏第一次编辑之前)不显示范围栏,在编辑时不显示范围栏,最后在编辑完成时显示它。我了解 UISearchBarDelegate 协议,但我不知道如何用动画显示/隐藏范围栏。我知道 UISearchBar 有 setShowsScopeBar:
,但没有 setShowsScopeBar:animated:
,就像 setShowsCancelButton:animated
那样。
编辑 在显示/隐藏范围栏后调用 [searchBar sizeToFit]
很重要。有没有一个好的方法来制作动画? (我应该这样做 这似乎不起作用。)
I want to show no scope bar when the table is empty (before the search bar edits for the first time), no scope bar when it's editing, and finally show it when editing done. I know about the UISearchBarDelegate protocol, but I don't know how to show/hide the scope bar with animation. I know UISearchBar has setShowsScopeBar:
, but no setShowsScopeBar:animated:
the way it does for setShowsCancelButton:animated
.
Edit
It's important that to call [searchBar sizeToFit]
after showing/hiding the scope bar. Is there a good way to animate this? (Should I do this? It doesn't appear to work.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是如何使取消按钮和范围栏仅在编辑时显示。
完整的代码,带有取消按钮(取消)外观动画的小好处:
编辑 - Swift 3 版本
来源:http://www.alexandre-gomes.com/?p=418
Here's how to make the cancel button and the scope bar to be displayed only while editing.
Complete code with the small bonus of animating the cancel button’s (dis)appearance:
EDIT - Version Swift 3
Source: http://www.alexandre-gomes.com/?p=418
对于较新的 iOS 版本(在 11-13 上测试),您不必实现任何委托方法即可使其工作。
在 iOS 13 中,默认行为是始终显示范围栏,即使当搜索未激活时。以前的 iOS 版本在搜索处于活动状态时会自动显示和隐藏范围栏。
您需要将其添加到
viewDidLoad()
中For the newer iOS versions (tested on 11-13), you don't have to implement any delegate methods for this to work.
In iOS 13 the default behaviour is to always show the scope bar, even when search is not active. Previous iOS versions automatically show and hide the scope bar when search is active.
You need to add this in
viewDidLoad()