ios - 导航项中的搜索 Controller 显示黑条

标签 ios swift uinavigationbar uisearchcontroller

您好,我已经使用设置搜索 Controller

private func setupSearchbar() {
        searchController = UISearchController(searchResultsController: nil)
        searchController.searchResultsUpdater = self
        searchController.obscuresBackgroundDuringPresentation = false
        searchController.searchBar.placeholder = "Search Contacts"

        self.navigationItem.searchController = searchController
        self.definesPresentationContext = true

    }

在我添加此代码之前一切都工作正常

    UINavigationBar.appearance().isOpaque = true
    UINavigationBar.appearance().isTranslucent = false
    UINavigationBar.appearance().barTintColor = UIColor(named: "PrimaryDark")
    UINavigationBar.appearance().tintColor = UIColor.white
    UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.font:Constants.AppTheme.Fonts.font(type: .FONT_BOLD, size: 22) ,NSAttributedString.Key.foregroundColor:UIColor.white]

    UINavigationBar.appearance().largeTitleTextAttributes   = [NSAttributedString.Key.font:Constants.AppTheme.Fonts.font(type: .FONT_BOLD, size: 34) ,NSAttributedString.Key.foregroundColor:UIColor.white]

现在,当我点击搜索栏时,会出现大底黑条

如何解决这个问题?

查看调试

enter image description here

enter image description here

最佳答案

好的,我可以解决这个问题。我分享此内容可能会对面临相同问题的其他人有所帮助。

解决这个问题。在 View 中将出现我已将 self.extendedLayoutIncludesOpaqueBars 设置为 true

的方法
 override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.extendedLayoutIncludesOpaqueBars = true

    }

希望对某人有帮助:)

这里是输出

enter image description here

关于ios - 导航项中的搜索 Controller 显示黑条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56250292/

相关文章:

ios - 如何在 iOS 应用程序 Swift 中更新 Pod

ios - 来自字符串的 MD5 哈希值不匹配

jquery - .on ("click") 不适用于 iOS

swift - 为什么我的 NSWindow 有一个工具栏?我怎样才能让它消失?

ios - 模态视图不覆盖整个屏幕

ios - 无法从导航栏中删除阴影

导航栏中不出现小延迟后添加的 iOS 搜索栏

iphone - NSDate到NSString的转换提供了不同的输出

ios - 当我改变它的大小时,我如何计算重绘 UIButton 的时间?

ios - 需要帮助隐藏/显示自定义 navBar IOS Swift