我正在尝试将 NSTextView 从一个 NSView 拖动到另一个 NSView。我收到了正确的事件,但拖动动画没有出现。
子类化 TextView:
class MyTextView:NSTextView, NSPasteboardItemDataProvider
{
func pasteboard(_ pasteboard: NSPasteboard?, item: NSPasteboardItem, provideDataForType type: NSPasteboard.PasteboardType)
{
NSLog ("Paste")
}
override func mouseDown(with theEvent: NSEvent)
{
let pasteboardItem = NSPasteboardItem()
pasteboardItem.setDataProvider(self, forTypes: [.string])
let draggingItem = NSDraggingItem(pasteboardWriter: pasteboardItem)
draggingItem.setDraggingFrame(self.bounds, contents:.Publisher)
beginDraggingSession(with: [draggingItem], event: theEvent, source: self)
}
override func draggingUpdated(_ sender: NSDraggingInfo) -> NSDragOperation
{
return NSDragOperation.copy
}
}
Run Code Online (Sandbox Code Playgroud)
子类化 NSView 以接收放置事件:
class DropView:NSView
{
func EnableDrop ()
{
// Registering for drag drop types …Run Code Online (Sandbox Code Playgroud)