我有一个基于文档的应用程序,其中窗口具有分割 View 。左侧 Pane 是 NSOutlineView,右侧 Pane 是显示元素的 Canvas 。
我目前支持 Canvas 和大纲 View 的拖放操作(两者应该具有相同的粘贴板类型,并且应该能够拖放到右侧或左侧 Pane 中)。
我想弄清楚如何识别拖动的源窗口。这样我就可以禁用在同一窗口内的 Canvas 或 NSOutlineView 上的拖放。我看到 NSDraggingInfo 有一个 DraggingSource 属性,但我无法使用它,因为它不是原始窗口。它还具有一个 DraggingDestinationWindow 属性,但没有用于源的属性。
知道如何解决这个问题吗?
更新
随着 Will 的使用draggingSource的插入,我重新审视了我的代码,并意识到我忽略了draggingSource的使用,因为有时我还处理来自Finder的拖动,当我尝试访问 NSView 的 window 属性时,它会崩溃。
我已经更新了以下方法的协议(protocol)实现
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
id<NSDraggingSource> dragSource = [sender draggingSource];
if ( [dragSource respondsToSelector:@selector(window)] && [(NSView *)dragSource window] == [self window])
return NO;
最佳答案
如果这一切都在一个应用程序中,您应该能够使用 draggingSource
This method returns nil if the source is not in the same application as the destination. The dragging source implements methods from the NSDraggingSource protocol.
关于objective-c - 如何识别 Cocoa 应用程序中拖动操作的源窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21242472/