【发布时间】:2020-02-23 02:26:50
【问题描述】:
我一直在尝试找出如何将图像的文件名放入 SwiftUI 视图中。
代码片段如下:
struct MainView: View, DropDelegate {
@ObservedObject var userState : UserState
var body : some View {
Group {
if (self.userState.editing) {
BlackoutView()
} else {
DropView()
}
}
.frame(minWidth: 320, idealWidth: 640, maxWidth: .infinity, minHeight: 240, idealHeight: 480, maxHeight: .infinity, alignment: .center)
.onDrop(of: [(kUTTypeImage as String), "public.pdf"], delegate: self)
}
func dropUpdated(info: DropInfo) -> DropProposal? {
let proposal = DropProposal.init(operation: .copy)
return proposal
}
func performDrop(info: DropInfo) -> Bool {
print("perform drop")
userState.editing = true
return true
}
}
当我将图像放到应用程序上时,它会运行 performDrop。怎样才能获得拖放到应用程序上的图像的文件名?
它在 macOS 上运行。
【问题讨论】:
标签: macos drag-and-drop swiftui