TableView标头中的UISearchController与其他项重叠

时间:2018-12-13 12:25:54

标签: ios swift

即使我为顶部标签和按钮设置了正确的约束,因此TableView也不重叠,但是在展开SearchBar时,它仍然重叠在屏幕的顶部和右侧。

添加SearchBar的{​​{1}}作为UISearchController的标题。

Image showing the problem

用于生成UISearchController和TableView的代码

TableView

//Create our search controller self._searchController = UISearchController(searchResultsController: nil) self._searchController?.searchResultsUpdater = self self._searchController?.obscuresBackgroundDuringPresentation = false self._searchController?.searchBar.placeholder = "Search for products or activities" self._searchController?.searchBar.sizeToFit() self._searchController?.searchBar.searchBarStyle = .minimal self._searchController?.searchBar.tintColor = UIColor.colorPrimary() self._searchController?.searchBar.barTintColor = #colorLiteral(red: 0.921431005, green: 0.9214526415, blue: 0.9214410186, alpha: 1) self._searchController?.searchBar.scopeButtonTitles = ["Products", "Activities"] self._searchController?.searchBar.selectedScopeButtonIndex = 0 self._searchController?.searchBar.delegate = self self.definesPresentationContext = true //Prepare our tableView self._tableView.rowHeight = UITableView.automaticDimension self._tableView.separatorStyle = .none self._tableView.showsVerticalScrollIndicator = false self._tableView.delegate = self self._tableView.dataSource = self self._tableView.register(ProductViewCell.nib, forCellReuseIdentifier: ProductViewCell.identifier) self._tableView.register(ActivityViewCell.nib, forCellReuseIdentifier: ActivityViewCell.identifier) self._tableView.tableHeaderView = self._searchController?.searchBar 处于活动状态时,我尝试将内容隐藏在顶部,并显示以下内容

SearchBar

但是,如果我想在使用滚动表格时使func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) { //self._titleLabel.fadeOut(0.0) //self._barCodeButton.fadeOut(0.0) } func searchBarTextDidEndEditing(_ searchBar: UISearchBar) { //self._titleLabel.fadeIn(1.0) //self._barCodeButton.fadeIn(1.0) } 散焦

SearchBar

SearchBar将保留,条目将消失,并且它们将再次重叠。

1 个答案:

答案 0 :(得分:0)

iOS11 +上UISearchController的默认选项是隐藏导航栏,并在搜索时向上移动搜索栏(带有动画)。

对于您的情况,我认为您只需要关闭此功能即可:

searchController.hidesNavigationBarDuringPresentation = false