iOS 16+设备相机界面显示异常标题问题求助
iOS 16+ 设备上 UIImagePickerController 相机界面标题显示异常
应用已上线运行,整体功能正常,但iOS 16+ 设备中使用UIImagePickerController实现的相机界面出现标题显示异常问题(附相关截图)。当前直接使用未做任何自定义修改的UIImagePickerController实现相机功能,核心代码如下:
let imagePicker = UIImagePickerController() imagePicker.delegate = self imagePicker.modalPresentationStyle = .overCurrentContext let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) alert.addAction(UIAlertAction(title: NSLocalizedString("Take photo".localized, comment: ""), style: .default, handler: { _ in #if targetEnvironment(simulator) #else imagePicker.sourceType = .camera imagePicker.cameraCaptureMode = .photo imagePicker.cameraDevice = .rear fbEvents.setButtonClickEvent(title: "ChangeProfileTakePhotoClickEvent", viewController: self) self.present(imagePicker, animated: true, completion: nil) #endif }))
解决方案
1. 调整模态展示样式
iOS 16 对UIImagePickerController的模态展示逻辑做了调整,.overCurrentContext样式可能干扰系统相机界面的导航栏布局。建议将模态样式改为系统默认的.fullScreen或.automatic:
imagePicker.modalPresentationStyle = .fullScreen // 或 .automatic
2. 显式控制导航栏标题
如果需要自定义标题或者修复系统默认标题的异常显示,可以在设置sourceType为.camera后,直接配置导航栏属性:
imagePicker.sourceType = .camera // 设置自定义标题 imagePicker.navigationBar.topItem?.title = "拍照" // 或者隐藏系统默认标题 imagePicker.navigationBar.topItem?.title = ""
3. 适配iOS 16+导航栏外观
iOS 16 中UINavigationBar的外观配置逻辑有更新,可通过全局外观代理统一设置,避免局部样式冲突:
if #available(iOS 16.0, *) { let navAppearance = UINavigationBarAppearance() navAppearance.configureWithDefaultBackground() UINavigationBar.appearance().standardAppearance = navAppearance UINavigationBar.appearance().scrollEdgeAppearance = navAppearance }
4. 验证本地化配置
检查"Take photo".localized对应的本地化文件是否在iOS 16+设备上正常加载,排除因本地化字符串缺失或加载异常导致的标题问题。
内容的提问来源于stack exchange,提问作者Krutika Sonawala
相关产品推荐
相关产品推荐

