使搜索栏保持在顶部
是否可以更改 iPhone 联系人应用程序类型的屏幕,使搜索栏始终位于顶部?如果是的话怎么办?
Is it possible to change the iphone contact application kind of screen to have the searchbar staying on the top always ? if yes how ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了方法。
这里是
I found out the way to do it.
here it is
我知道这是一个老问题,但我找到了一个解决方案,它与经典的 UITableViewController 和 UTSearchDisplayController 一起使用。
我首先为 searchBar 创建了一个容器视图,然后将搜索栏放入其中。容器不得剪裁到边界。之后,您可以更改搜索栏相对于容器的位置。这样做的一个问题是搜索栏无法处理用户交互。所以我们需要使用我们自己的容器来获取低于其真实框架的事件。
我们的容器类:
如果您以编程方式创建 searchBar,您可以使用以下类似代码进行设置:
然后您可以根据 tableView 的滚动位置更改位置:
最后一部分是在搜索后恢复所有内容:
I know it's an old question, but I found out a solution for this, which works with the classic UITableViewController and UTSearchDisplayController.
I created a container view for the searchBar 1st then put the searchbar inside it. The container must not clip to bounds. After this you can change the position of the searchbar relative to the container. One problem with this that this way the searchbar not handle user interactions. So we need to use our own container which get the events below its real frame.
Our container class:
If you create the searchBar programmatically you can set the this up with a following like code:
Then you can change the position based on the tableView's scroll position:
And the last part is to restore everything after searching: