MacOS/Appkit:无法看到 NSTextView 的拖动动画

Sid*_*air 5 macos nsview nstextview appkit swift

我正在尝试将 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

        registerForDraggedTypes([NSPasteboard.PasteboardType.string, NSPasteboard.PasteboardType.URL, NSPasteboard.PasteboardType.multipleTextSelection, NSPasteboard.PasteboardType.color])
    }

    func shouldAllowDrag(_ draggingInfo: NSDraggingInfo) -> Bool 
    {
        
      return true
      
    }

    override func draggingEntered(_ sender: NSDraggingInfo) -> NSDragOperation {

        // To show a copy tooltip during drop

        return NSDragOperation.copy
    }

    override func prepareForDragOperation(_ sender: NSDraggingInfo) -> Bool 
    {
        
      return true
    }

    override func performDragOperation(_ draggingInfo: NSDraggingInfo) -> Bool {
        
        let draggedview = draggingInfo.draggingSource as! NSView
        
        NSLog ("Drop received")
        
        return true
    }
}
Run Code Online (Sandbox Code Playgroud)

当我在 ViewController 中创建视图时,我执行“myviewobj.EnableDrop()”来接收放置事件。然而,如上所述,我无法看到拖动动画的发生,但是,我确实收到了它的事件。