【问题标题】:Status Bar becomes white in iOS when using UISearchController in iOS 13在 iOS 13 中使用 UISearchController 时,状态栏在 iOS 中变为白色
【发布时间】:2019-10-09 20:21:40
【问题描述】:

这里有一个奇怪的情况。当我使用UISearchController 时,我首先得到了这个外观(如预期的那样)

但是当您在 TextField 内选择开始搜索时,状态栏会变成全白(如果您处于暗模式,则为黑色)

这从未发生过。 UISearchController 中是否有一些设置告诉它在使用搜索栏时使用某种状态栏样式?

我希望它保持选择 TextField 之前的颜色

---编辑---

override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: UIBarButtonItem.Style.plain, target: nil, action: nil)

    frc = getFRC()
    frc.delegate = self

    self.resultsSearchController.delegate = self
    let searchBar = self.resultsSearchController.searchBar

    self.resultsSearchController.searchResultsUpdater = self
    self.resultsSearchController.obscuresBackgroundDuringPresentation = false
    self.resultsSearchController.extendedLayoutIncludesOpaqueBars = true

    searchBar.sizeToFit()
    self.tableView.tableHeaderView = searchBar
    searchBar.placeholder = "Catalog Search"
    searchBar.barTintColor = UIColor.darkAqua
    searchBar.searchTextField.backgroundColor = UIColor.white

    self.definesPresentationContext = true

    searchBarHeight = searchBar.frame.height

    do {
        try frc.performFetch()
    } catch {
        error.tryError(tryMessage: "Perform initial fetch", loc: self)
    }

    if tutorials.catalog {
        createTutorialTab(segueNameOnOpen: "catalogTutorial")
    }
}

【问题讨论】:

  • 如果键盘出现,你调整框架?这可能是问题之一。
  • 不,没有调整框架。
  • 您要更改状态栏或导航栏的属性吗?即 .backgroundColor = .white?
  • 不,那里也没有。我会在上面发布我的viewDidLoad
  • 只是一个预感..你可以尝试使用这条线 self.resultsSearchController.hidesNavigationBarDuringPresentation = false

标签: ios swift uisearchcontroller


【解决方案1】:

你使用这个函数来改变状态栏的颜色,这是处理状态栏的一种技巧;)。如果您在整个应用中使用一个主题状态栏,请从 AppDelegate 中的 didFinishLaunching 调用此函数。

func changeStatusBar(backgroundColor: UIColor, contentColor:UIColor) {

    if let statusBar = UIApplication.shared.value(forKey: "statusBar") as? UIView {
        statusBar.backgroundColor = backgroundColor
        statusBar.setValue(contentColor, forKey: "foregroundColor")
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-23
    • 2013-12-02
    • 1970-01-01
    • 2020-06-16
    • 1970-01-01
    • 2018-01-24
    • 2020-01-21
    • 1970-01-01
    相关资源
    最近更新 更多