如何像iPhone设置一样打开UISearchBar搜索栏? [英] How to open UISearchBar like iPhone settings search bar?

查看:91
本文介绍了如何像iPhone设置一样打开UISearchBar搜索栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有简单的方法来处理 UISearchBar 位置,类似于 iPhone设置搜索栏?因为iPhone设置搜索栏正在打开,同时下拉屏幕并打开由我们的拉动操作控制的动画。

Is there any easy way to handle UISearchBar position similar to iPhone settings search bar? Because iPhone settings search bar is opening while pull down the screen and open animation controlled by our pull action.

我想在我的应用中执行相同的操作。

I want to do the same in my app. Help me if any easy way you know.

谢谢

推荐答案

我认为实现此动画的最简单方法是:

I think the easiest way to achieve this animation is:

在添加搜索时显示/隐藏搜索栏将是 default 行为单元格顶部的滚动视图(表格视图)内的栏:

It would be the default behavior for showing/hiding the search bar when adding the search bar inside the scroll view (table view) on top of the cell(s):

通过应用上述内容,向下滚动将使搜索栏隐藏(折叠),反之亦然:

By applying the above, scrolling to down would let the search bar to be hidden (collapsed) and vise versa:

我认为没有更多可做的事情。

I assume that there is nothing to do more.

如果您希望默认情况下隐藏搜索栏,则可以通过将表格视图滚动到顶部(您可能想在 viewDidLoad()中调用它)来实现它(作为一种解决方法):

if you want to let the search bar to be hidden by default, you could achieve it -as a workaround- by scrolling the table view to the top (you might want to call this in the viewDidLoad()):

let searchBarHeight = searchBar.frame.size.height
tableView.setContentOffset(CGPoint(x: 0, y: searchBarHeight), animated: false))

这篇关于如何像iPhone设置一样打开UISearchBar搜索栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆