gpt4 book ai didi

uisearchcontroller - iOS 13 : Dismiss UISearchController on navigation item causes the tintColor reversing back to default

转载 作者:行者123 更新时间:2023-12-02 09:06:06 24 4
gpt4 key购买 nike

我在导航项上使用 UISearchController(导航栏已设置为使用 barTintColor 和 twinColor)。当搜索 Controller 关闭(点击搜索栏的取消按钮)时,后退按钮的色调颜色将反转回默认值(蓝色)。

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

屏幕截图 2:当 UISearchController 处于事件状态时: enter image description here

屏幕截图 3:当 UISearchController 关闭时(通过点击“取消”) - 您可以看到“后退”按钮的色调颜色反转回默认值(蓝色),而不是白色: 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
}

}

}

最佳答案

我也遇到了同样的问题。尝试了一切方法来修复它。结果是,这绝对是 iOS 13 错误,因为即使像 Notes 这样的系统应用程序也会这样做。希望 Apple 能够在下一次 iOS 更新中修复这个问题。

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

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

Step 1

点击取消后

Step 2

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

关于uisearchcontroller - iOS 13 : Dismiss UISearchController on navigation item causes the tintColor reversing back to default,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58412236/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com