iOS 13:关闭导航项上的UISearchController会导致tintColor恢复为默认值

问题描述 投票:1回答:1

我正在导航项目上使用UISearchController(已将导航栏设置为使用barTintColor和tintColor)。关闭搜索控制器后(点击搜索栏的“取消”按钮),后退按钮的tintColor将恢复为默认值(蓝色)。

屏幕截图1:导航栏的tintColor为.whiteenter image description here

截屏2:当UISearchController处于活动状态时:enter image description here

截屏3:关闭UISearchController时(通过点按“取消”)-您可以看到“返回”按钮的tintColor被反向设置为默认值(蓝色),而不是白色:enter image description here

屏幕截图上的代码是:


/// View controller is embedded in a UINavigationController, the root view controller of the startup storyboard.
class ViewController: UIViewController {

  lazy var searchController: UISearchController = {
    let controller = UISearchController(searchResultsController: nil)
    controller.searchBar.tintColor = .white
    return controller
  }()

  override func viewDidLoad() {
    super.viewDidLoad()
    if let navigationBar = navigationController?.navigationBar {
      setupNavigationBar(navigationBar)
    }
    if #available(iOS 11.0, *) {
      navigationItem.searchController = searchController
    } else {
      navigationItem.titleView = searchController.searchBar
    }
  }

  func setupNavigationBar(
    _ navigationBar: UINavigationBar,
    barTintColor: UIColor = .red,
    tintColor: UIColor = .white,
    textColor: UIColor = .white,
    prefersLargeTitles: Bool = true,
    isTranslucent: Bool = false) {

    navigationBar.isTranslucent = isTranslucent
    navigationBar.barTintColor = barTintColor

    if #available(iOS 11.0, *) {
    } else {
      navigationBar.setBackgroundImage(UIImage(), for: .default)
    }
    navigationBar.shadowImage = UIImage()

    navigationBar.tintColor = tintColor
    navigationBar.titleTextAttributes = [
      .font: UIFont.preferredFont(forTextStyle: .headline),
      .foregroundColor: textColor
    ]

    if #available(iOS 11.0, *) {
      navigationBar.prefersLargeTitles = prefersLargeTitles
      navigationBar.largeTitleTextAttributes = [
        .font: UIFont.preferredFont(forTextStyle: .largeTitle),
        .foregroundColor: textColor
      ]
    }

    if #available(iOS 13.0, *) {
      let navBarAppearance = UINavigationBarAppearance()
      navBarAppearance.configureWithOpaqueBackground()
      navBarAppearance.titleTextAttributes = navigationBar.titleTextAttributes ?? [:]
      navBarAppearance.largeTitleTextAttributes = navigationBar.largeTitleTextAttributes ?? [:]
      navBarAppearance.backgroundColor = barTintColor
      navBarAppearance.shadowColor = barTintColor
      navigationBar.standardAppearance = navBarAppearance
      navigationBar.scrollEdgeAppearance = navBarAppearance
    }

  }

}

uisearchcontroller ios13 tintcolor
1个回答
4
投票

我有同样的问题。尝试了所有修复程序。结果是这肯定是iOS 13 bug,因为即使是像Notes之类的系统应用程序也一样。希望苹果能在下一个iOS更新中修复它。

下面是Notes应用程序的屏幕截图。

在点击搜索栏中的取消按钮之前

Step 1

点击取消后

Step 2

更新。 iOS 13.2已发布,并且此错误似乎已修复✅

© www.soinside.com 2019 - 2024. All rights reserved.