UIImagePickerController 横向模式切换屏幕

UIImagePickerController landscape mode shifts screen

我正在尝试做一个简单的 SwiftUI 应用程序,它可以打开相机或允许用户从图库中选择照片。目前,当我在打开的相机视图中将 phone 旋转到横向模式时,由于某种原因整个界面移到屏幕外。

调用UIImagePickerController的代码:

struct CaptureImageView {
@Binding var isShown: Bool
@Binding var image: UIImage?
@Binding var sourceType: UIImagePickerController.SourceType
@Binding var imageSelected: Bool

func makeCoordinator() -> Coordinator {
    return Coordinator(isShown: $isShown, image: $image, imageSelected: $imageSelected)
}}

extension CaptureImageView: UIViewControllerRepresentable {
func makeUIViewController(context: UIViewControllerRepresentableContext<CaptureImageView>) -> UIImagePickerController {
    let picker = UIImagePickerController()
    picker.sourceType = sourceType
    picker.delegate = context.coordinator
    picker.allowsEditing = true
    picker.setEditing(true, animated: true)
    if (picker.sourceType == .camera) {
        picker.cameraCaptureMode = .photo
    }
    return picker
}

func updateUIViewController(_ uiViewController: UIImagePickerController,
                            context: UIViewControllerRepresentableContext<CaptureImageView>) {
    
}}

旋转屏幕时的样子:

有没有合适的方法让它根据方向变化调整视图?

似乎唯一可行的解​​决方案是 portrait-locking 整个应用程序。

经验教训:Swift-UI 绝对是垃圾。