UINavigationBar变成白色,在iOS 13中使用navigationItem.searchController时不会关闭

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

[我在iOS 13中无法使用navigationItem.searchController。搜索控制器的搜索栏最初是关闭的,但是在滚动表格视图后它不会折叠回去。当我尝试隐藏栏时,它会“反弹”。

[此外,出现搜索栏后,导航栏也会变成白色。(导航栏具有自定义的颜色;请参阅所附的屏幕截图。)请注意,在iOS <13中不是这种情况。

这是iOS 13中的错误吗?如果是,是否有变通办法来保持导航栏的色调颜色并在向上滚动表视图时隐藏搜索栏?

[在表格视图中填充单元格以填充屏幕时,搜索栏似乎隐藏了。

以下是我的ViewController的代码,它嵌入在UINavigationController中:

class ViewController: UITableViewController {
  override func viewDidLoad() {
    super.viewDidLoad()
    navigationItem.searchController = UISearchController(searchResultsController: nil)
  }
}

屏幕截图:

iOS 13.2iOS 12.2

swift uinavigationbar uisearchbar ios13 uisearchcontroller
1个回答
0
投票

我设法使用新的UINavigationBarAppearance API'修复'了新的行为,但是我仍然无法获得导航栏的原始半透明外观并使它折叠。

UINavigationBar.appearance().isTranslucent = true似乎无法与新API一起使用,因此我只是使用颜色选择器将颜色调整为与半透明版本匹配。

而且,似乎也没有办法正确折叠搜索栏。

class AppDelegate: UIResponder, UIApplicationDelegate {
  func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?)
    -> Bool
  {
    if #available(iOS 13.0, *) {
      let appearance = UINavigationBarAppearance()
      appearance.configureWithOpaqueBackground()
      appearance.backgroundColor = .redAdjusted  // adjusted to match the translucent version
      appearance.titleTextAttributes = [.foregroundColor: UIColor.white]
      appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]

      UINavigationBar.appearance().standardAppearance = appearance
      UINavigationBar.appearance().scrollEdgeAppearance = appearance
    } else {
      UINavigationBar.appearance().tintColor = .white
      UINavigationBar.appearance().barTintColor = .red
      UINavigationBar.appearance().isTranslucent = true
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.