在开始时隐藏自定义搜索栏
hide custom search bar on start
在我的 swift 2 应用程序中,我有一个 table 视图控制器
我在其中添加了自定义搜索栏(深灰色行)
在我调用的 viewDidLoad 中
configureCustomSearchController()
这是函数:
func configureCustomSearchController() {
customSearchController = CustomSearchController(
searchResultsController: self,
searchBarFrame: CGRectMake(0.0, 0.0, MyTable.frame.size.width, 50.0),
MyTable.tableHeaderView = customSearchController.customSearchBar
customSearchController.searchBar.sizeToFit()
customSearchController.customDelegate = self
}
func updateSearchResultsForSearchController(searchController: UISearchController) {
// DO SOMETHING
}
func didStartSearching() {
// DO SOMETHING
}
func didTapOnSearchButton() {
// DO SOMETHING
}
func didTapOnCancelButton() {
// DO SOMETHING
}
func didChangeSearchText(searchText: String) {
// DO SOMETHING
}
我的问题是,如果我的table视图会出现并在下拉时显示边栏,我该如何隐藏搜索器。
有下拉刷新功能。
如果您想在用户向下滚动时显示搜索栏,请添加此代码
self.MyTable.tableHeaderView = customSearchController
self.MyTable.contentOffset = CGPointMake(0, CGRectGetHeight(customSearchController.frame))
customSearchController.delegate = self
如果您想隐藏包含自定义搜索栏的 header,您可以尝试以下解决方案:
当你必须隐藏时 header(开始时):
tableview.contentOffset = CGPointMake(0,44)
当你必须显示 header(下拉动作时):
tableview.contentOffset = CGPointMake(0,0)
参考:https://whosebug.com/a/14433304/4557505
另一种选择是
table.tableHeaderView = nil
以后如果你想显示它就再分配一次,
table.tableHeaderView = theHeaderView;
您可以在 https://whosebug.com/a/8079933/4557505
上找到更多相关信息
希望这对您有所帮助
否则,您可以将搜索栏设置在 viewController 的视图上,show/hide 根据您的下拉刷新
我找到了我的解决方案:
viewDidLoad
MYTable.contentInset = UIEdgeInsets(top: -1, left: 0, bottom: 0, right: 0)
这会在开始时隐藏搜索栏,如果我向上滚动一点,搜索栏就会可见
在我的 swift 2 应用程序中,我有一个 table 视图控制器 我在其中添加了自定义搜索栏(深灰色行)
在我调用的 viewDidLoad 中
configureCustomSearchController()
这是函数:
func configureCustomSearchController() {
customSearchController = CustomSearchController(
searchResultsController: self,
searchBarFrame: CGRectMake(0.0, 0.0, MyTable.frame.size.width, 50.0),
MyTable.tableHeaderView = customSearchController.customSearchBar
customSearchController.searchBar.sizeToFit()
customSearchController.customDelegate = self
}
func updateSearchResultsForSearchController(searchController: UISearchController) {
// DO SOMETHING
}
func didStartSearching() {
// DO SOMETHING
}
func didTapOnSearchButton() {
// DO SOMETHING
}
func didTapOnCancelButton() {
// DO SOMETHING
}
func didChangeSearchText(searchText: String) {
// DO SOMETHING
}
我的问题是,如果我的table视图会出现并在下拉时显示边栏,我该如何隐藏搜索器。
有下拉刷新功能。
如果您想在用户向下滚动时显示搜索栏,请添加此代码
self.MyTable.tableHeaderView = customSearchController
self.MyTable.contentOffset = CGPointMake(0, CGRectGetHeight(customSearchController.frame))
customSearchController.delegate = self
如果您想隐藏包含自定义搜索栏的 header,您可以尝试以下解决方案:
当你必须隐藏时 header(开始时):
tableview.contentOffset = CGPointMake(0,44)
当你必须显示 header(下拉动作时):
tableview.contentOffset = CGPointMake(0,0)
参考:https://whosebug.com/a/14433304/4557505
另一种选择是
table.tableHeaderView = nil
以后如果你想显示它就再分配一次,
table.tableHeaderView = theHeaderView;
您可以在 https://whosebug.com/a/8079933/4557505
上找到更多相关信息希望这对您有所帮助
否则,您可以将搜索栏设置在 viewController 的视图上,show/hide 根据您的下拉刷新
我找到了我的解决方案:
viewDidLoad
MYTable.contentInset = UIEdgeInsets(top: -1, left: 0, bottom: 0, right: 0)
这会在开始时隐藏搜索栏,如果我向上滚动一点,搜索栏就会可见