我正在像这样添加搜索 Controller :
viewController.navigationItem.searchController = searchController
viewController.navigationItem.hidesSearchBarWhenScrolling = false
viewController.definesPresentationContext = true
searchController.dimsBackgroundDuringPresentation = false
searchBarContainer.translatesAutoresizingMaskIntoConstraints = false
searchBarContainer.heightAnchor.constraint(equalToConstant: 0).isActive = true
当尝试向右滑动以弹出当前 viewController(交互式弹出手势在此处激活)但停留在同一个 Controller 上时,搜索栏就会消失。
viewController.navigationItem.searchController
保存添加的搜索 Controller ,但它不可见。
最佳答案
尝试将此代码添加到任何 viewController
类是以下实例的实例:
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.definesPresentationContext = true
}
这对我有用。
关于swift - 发生交互式弹出手势时搜索栏消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47994432/