在我的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
}这很有效-直到我想要显示来自我的UIViewControllers之一的UIImagePickerController -图像超出了条形图,因为它是半透明的-我需要能够暂时使导航栏变为白色,然后在取消拾取器控制器时再次使其半透明:

我尝试通过将最后两行添加到代码中来修复此问题:
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)不过,这似乎不起作用。
发布于 2019-11-17 02:53:08
试试这个:
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 = truehttps://stackoverflow.com/questions/58893545
复制相似问题