[显示UIImagePickerController时更新导航栏背景

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

在我的AppDelegate中,我的导航栏配置如下:

func setupNavBar() {
    let barAppearance = UINavigationBar.appearance()
    barAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: appRed]
    barAppearance.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
    barAppearance.shadowImage = UIImage()
    barAppearance.isTranslucent = true
}

这很好-直到我要显示我的UIImagePickerController中的一个UIViewControllers-图像都超出了半透明条的限制-我需要能够暂时将导航栏变白,然后再使其变白取消选择器控制器后再次变为半透明:

enter image description here

我尝试通过将最后两行添加到代码中来解决此问题:

 let pickerController = UIImagePickerController()
    pickerController.delegate = self
    pickerController.allowsEditing = false
    pickerController.mediaTypes = ["public.image"]
    pickerController.sourceType = .savedPhotosAlbum
    self.navigationController?.navigationBar.backgroundColor = .white
    self.navigationController?.navigationBar.isTranslucent = false
    self.present(pickerController, animated: true, completion: nil)

这似乎不起作用。

ios swift uinavigationcontroller uinavigationbar uiimagepickercontroller
1个回答
0
投票

尝试一下:

let pickerController = UIImagePickerController()
pickerController.delegate = self
pickerController.allowsEditing = false
pickerController.mediaTypes = ["public.image"]
pickerController.sourceType = .savedPhotosAlbum
UINavigationBar.appearance().isTranslucent = false
self.present(pickerController, animated: true, completion: nil)

并且在图像选择器上关闭

UINavigationBar.appearance().isTranslucent = true
© www.soinside.com 2019 - 2024. All rights reserved.