隐藏导航控制器搜索栏 &以编程方式打开大标题 [英] Hide Navigation Controller Search Bar & opened Large Title programmatically

查看:22
本文介绍了隐藏导航控制器搜索栏 &以编程方式打开大标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 tableView.我设置了有关 searchController(大导航栏中的搜索栏)的所有设置 - (滚动 tableview 时打开/关闭).我实现了 rightBarButtonItem 名称为 'Close' .我想以编程方式隐藏/关闭 tableView 和搜索栏.我可以隐藏 tableView 但不能隐藏 SearchBar.

I have a tableView. I set the all settings about searchController ( Search Bar in Large Navigation Bar ) - ( open / close when scroll tableview ). I implemented rightBarButtonItem which name is 'Close' . I want to hide/close tableView and Search Bar with programmatically. I can hide tableView but not SearchBar.

当我为 SearchBar 执行 isHidden 时,大导航栏不会缩小到正常大小.

When I do isHidden for SearchBar , The Large Navigation Bar doesnt shrink to normal size.

图 1. 向下滚动打开搜索栏.

Pic 1. Opened search bar with scroll down.

Pic 2. Not Hidden Large Navigation Bar with programmatically (searchar.isHidden 没有在这里实现)

Pic 2. Not Hidden Large Navigation Bar with programmatically ( searchar.isHidden not implemented here )

提前致谢.

我以前试过这个,但没有运行

I tried this before but not run

tableView.setContentOffset(.zero, animated: false)
navigationController?.navigationBar.prefersLargeTitles = false

推荐答案

我试图找到一种隐藏搜索栏的正确方法,但我没有找到.但我找到了一种隐藏搜索栏的解决方法,即更改内容偏移您的表格视图.

I tried to find a proper way to hide search bar, but I didn't find. But I found a workaround to hide your search bar which is change content offset your table view.

你可以试试这个功能来隐藏你的表格视图和搜索栏.

You may try this function to hide your table view and search bar.

func hide() {
    tableView.isHidden = true
    let point = tableView.contentOffset
    let searchBarFrame = self.navigationItem.searchController?.searchBar.frame
    let newPoint = CGPoint(x: point.x, y: point.y + searchBarFrame!.height)
    tableView.setContentOffset(newPoint, animated: true)
}

这篇关于隐藏导航控制器搜索栏 &以编程方式打开大标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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