如何在iOS 15&#x2B中修复Navbar UiimagePickerController保持透明

发布于 2025-02-10 08:41:55 字数 799 浏览 2 评论 0原文

设备使用时,我对uiimagePickerController有问题

iOS 15 =“ https://i.sstatic.net/mdhab.jpg” alt =“在此处输入图像说明”> 我的期望是Navbar像15岁以下的iOS设备一样保持白色 我使用了此方法,但是它不起作用,有没有办法解决此问题?

let picker = UIImagePickerController()
picker.sourceType = .photoLibrary
picker.delegate = self
picker.modalPresentationStyle = .overCurrentContext
        
if #available(iOS 13.0, *) {
    let appearance = UINavigationBarAppearance()
    appearance.configureWithOpaqueBackground()
    appearance.backgroundColor = .white
    appearance.shadowColor = .white
    appearance.shadowImage = UIImage()
            
    picker.navigationBar.standardAppearance = appearance
    picker.navigationBar.scrollEdgeAppearance = appearance
}

viewController.present(picker, animated: true, completion: nil)

谢谢

I have a problem with UIImagePickerController when used by iOS 15 device because the navigation bar has a transparent background,

enter image description here
my expectation is the navbar to stay white like on ios devices below 15
I've used this method but it doesn't work, is there a way to fix this issue?

let picker = UIImagePickerController()
picker.sourceType = .photoLibrary
picker.delegate = self
picker.modalPresentationStyle = .overCurrentContext
        
if #available(iOS 13.0, *) {
    let appearance = UINavigationBarAppearance()
    appearance.configureWithOpaqueBackground()
    appearance.backgroundColor = .white
    appearance.shadowColor = .white
    appearance.shadowImage = UIImage()
            
    picker.navigationBar.standardAppearance = appearance
    picker.navigationBar.scrollEdgeAppearance = appearance
}

viewController.present(picker, animated: true, completion: nil)

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光倒影 2025-02-17 08:41:55

根据 Apple论坛上的一些旧问题它的导航栏似乎参考picker.navigationbar.standardappearance无法真正更改Picker的外观,唯一不幸的解决方案是为所有uinavigationbars全局更改外观,通过同样设置其外观:

UINavigationBar.appearance().standardAppearance = appearance

也可以 :检查您是否没有偶然地在代码中的某个地方修改全局显示。
希望它可以帮助您,即使它不是最佳解决方案。

According to some old question on Apple forum regarding UIImagePickerController and its navigationBar it seems that referencing picker.navigationBar.standardAppearance cannot really change picker appearence and the only unfortunate solution is to globally change appearence for all UINavigationBars by setting its appearence likewise:

UINavigationBar.appearance().standardAppearance = appearance

Also check if you are not modifying the global appearence somewhere in your code by accident.
Hopefully it helps you, even though it is propably not optimal solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文