因此,我正在关注UISearchController上的this教程,并对其进行了一些修改。我在RedViewController
之前创建了SearchViewController
,在其中隐藏了导航栏。正如您在动画中看到的那样,从SearchViewController
到RedViewController
展开对于搜索栏来说并不好。此外,如果您没有完成放松过程(向后滑动,然后向前滑动),则整个搜索栏都会消失。我尝试关闭viewWillDisappear
上的搜索控制器,但没有用。
SearchViewController:
override func viewDidLoad() {
super.viewDidLoad()
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search Candies"
navigationItem.searchController = searchController
definesPresentationContext = true
}
override func viewWillDisappear(_ animated: Bool) {
navigationItem.searchController?.dismiss(animated: false)
}
RedViewController:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.setNavigationBarHidden(false, animated: animated)
}