简体   繁体   English

UISearchController和NavigationBar回来了

[英]UISearchController and NavigationBar back

I'm addapting this code in my project https://github.com/stuartbreckenridge/UISearchControllerWithSwift 我在我的项目https://github.com/stuartbreckenridge/UISearchControllerWithSwift中添加了这段代码

After Navigation Controller and before Countries Scene (ViewController) I have put one more View Controller, so now in Countries View controller I have back button. 导航控制器之后和国家场景之前(ViewController)我已经放了一个View Controller,所以现在在Countries View控制器中我有后退按钮。 After inputing something in search bar when I press Back, search bar still is visible. 按Back后,在搜索栏中输入内容后,搜索栏仍然可见。

I've tried hide it doing this (countrySearchController is UISearchController): 我试过隐藏它这样做(countrySearchController是UISearchController):

override func viewWillDisappear(animated: Bool) {
    self.countrySearchController.active = false
}

But it hides UISearchController with delay, so it's stil visible for half a second. 但它隐藏了UISearchController的延迟,因此它可以看到半秒钟。

Input something: 输入内容: 在此输入图像描述

And then press back: 然后按下: 在此输入图像描述

Correct way probably is to set self.definesPresentationContext in viewDidLoad 正确的方法可能是在viewDidLoad设置self.definesPresentationContext

self.definesPresentationContext = true

That caused some glitches when UISearchController became active, so I just removed the searchBar from Superview . UISearchController变为活动状态时,这会引起一些故障,所以我只是从Superview删除了searchBar

override func viewWillDisappear(animated: Bool) {
    searchController.searchBar.removeFromSuperview()
    searchController.active = false;
    super.viewWillDisappear(true)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM