swift - 发生交互式弹出手势时搜索栏消失

标签 swift ios11 uisearchcontroller interactivepopgesture

我正在像这样添加搜索 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/

相关文章:

swift - 验证纹理尺寸:759: failed assertion `MTLTextureDescriptor has width (45000) greater than the maximum allowed size of 16384.'

post - 解决 WKWebView http POST 不再在 iOS 11.3 中发送参数

ios - 使用 UISearchController 在 Navigationbar 中实现搜索栏

ios - iOS 11.3 的网络推送通知

swift - 如何从 UINavigationItem 中关闭 UISearchController?

ios - 如何在 UIBarButtonItem 中放置 UISearchBar?

ios - 当第一个 View Controller 在 iOS 中隐藏其导航栏时,向后滑动会导致导航栏立即隐藏(不平滑)

swift - 实现 LazyCollectionProtocol

swift - inputAccessoryView 不显示

ios - 如何突出显示 UITextField 内的部分文本?