【问题标题】:How do I implement drag-and-drop from Photos to my Cocoa app with full quality?如何实现从照片到我的 Cocoa 应用程序的高质量拖放?
【发布时间】:2019-02-23 14:45:42
【问题描述】:

在我的拖动目标视图(NSView 子类)中,我实现了:

override func performDragOperation(_ draggingInfo: NSDraggingInfo) -> Bool {

    // check for Photos promises
    var gotPromised = false
    draggingInfo.enumerateDraggingItems(options: [], for: self, classes: [NSFilePromiseReceiver.self], searchOptions: [:], using: {(draggingItem, idx, stop) in
        let filePromiseReceiver = draggingItem.item
        print("got a file promise receiver: \(filePromiseReceiver)")
        gotPromised = true
        // Use filePromiseReceiver here for your task.
    })
    return gotPromised
}

当我运行它并从 Photos.app 中拖动一些东西时,我收到了以下警告:

如何修复我的拖动目的地不出现此警告?我想在我的应用程序中添加高质量的照片。

【问题讨论】:

  • 视图接受哪些粘贴板类型?
  • 是的……不包括承诺。

标签: cocoa drag-and-drop photo nsdragginginfo nsdraggingdestination


【解决方案1】:

嗯。经过一番调查,我自己想通了。您需要做多件事(注册正确的类型,正确枚举项目等),如果您只是完全正确地实现承诺接收,则不会出现警告。 Apple 提供了一个example project,它正确地实现了一切。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多