小编Sid*_*air的帖子

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

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

macos nsview nstextview appkit swift

5
推荐指数
0
解决办法
45
查看次数

标签 统计

appkit ×1

macos ×1

nstextview ×1

nsview ×1

swift ×1