Vas*_*rov 5 uiimagepickercontroller swift ios13
我正在展示一个UIImagePickerController选择图像。我的代码很简单:
private lazy var imagePicker: UIImagePickerController = {
let picker = UIImagePickerController()
picker.navigationBar.isTranslucent = false
return picker
}()
func presentPicker() {
imagePicker.sourceType = .photoLibrary
imagePicker.modalPresentationStyle = .fullScreen
present(self.imagePicker, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
我设置picker.navigationBar.isTranslucent = false在选择器控制器中有一个不透明的导航栏。不幸的是,这不适用于 iOS 13,并且导航和状态栏是透明的。
部分解决方案:
private func setOpaqueNavigationiOS13() {
UINavigationBar.appearance().backgroundColor = .white
}
private func resetNavigationiOS13() {
UINavigationBar.appearance().backgroundColor = .clear
}
Run Code Online (Sandbox Code Playgroud)
我调用上述函数使导航栏不透明并在关闭选择器时将其重置。这使得导航栏不透明,但状态栏是透明的。我也可以实现一个 hack 使状态栏不透明,但我想应该有一个更简单的解决方案。
编辑:我还尝试通过新的 UINavigationBarAppearance 设置导航栏的外观:
if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = .white
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().compactAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
}
Run Code Online (Sandbox Code Playgroud)
或者:
if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = .white
imagePicker.navigationBar.standardAppearance = appearance
imagePicker.navigationBar.compactAppearance = appearance
imagePicker.navigationBar.scrollEdgeAppearance = appearance
}
Run Code Online (Sandbox Code Playgroud)
有想出解决办法的人吗?谢谢
mat*_*att -1
在 iOS 13 中,自定义导航栏外观的正确方法是通过 UIBarAppearance 架构(导航栏standardAppearance等)。您可以将其直接应用于导航栏或使用 UINavigationBar 外观代理。
| 归档时间: |
|
| 查看次数: |
1473 次 |
| 最近记录: |