提问人:Sidharth Mahesh Nair 提问时间:11/15/2023 更新时间:11/15/2023 访问量:42
MacOS/Appkit:无法看到 NSTextView 的拖动动画
MacOS/Appkit: unable to see drag animations for an 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
}
}
子类化 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
}
}
当我在 ViewController 中创建视图时,我执行“myviewobj.EnableDrop()“来接收丢弃事件。但是,如上所述,我无法看到拖动动画的发生,但是,我确实收到了它的事件。
答: 暂无答案
评论
NSDraggingItem