因此,我一直在忙于将一个小型 SwiftUI iPad 应用程序“移动”到 Mac 上,并且在使用UIDocumentPickerViewController
. 我已经像这样包裹UIDocumentPickerViewController
了UIViewControllerRepresentable
:
struct DocumentPickerView: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIDocumentPickerViewController {
let documentPicker = UIDocumentPickerViewController(documentTypes: [(kUTTypeImage as String)], in: .import)
return documentPicker
}
func updateUIViewController(_ uiViewController: UIDocumentPickerViewController, context: Context) {
}
}
并像这样显示它:
struct ContentView: View {
@State var shows = false
var body: some View {
Button(action: { self.shows.toggle() }) {
Text("Select File")
}
.sheet(isPresented: self.$shows) {
DocumentPickerView()
}
}
}
但是当在 Mac 上时,UIDocumentPickerViewController
不显示,我们得到这个空白模式: