删除 IKImageBrowserView 的拖放行为
-
27-09-2019 - |
题
默认情况下(看起来),IKImageBrowserView 允许拖放到 Finder 中的位置。我想关闭此行为,但不确定如何操作。我在想也许实现 NSDraggingDestination 协议并覆盖它可以解决这个问题,但到目前为止它对我来说还没有用。
谢谢你的帮助!
解决方案
如果你想定制IKImageBrowserView的拖放行为,可以实现在浏览器中的数据源对象的- (NSUInteger) imageBrowser:(IKImageBrowserView *) aBrowser writeItemsAtIndexes:(NSIndexSet *) itemIndexes toPasteboard:(NSPasteboard *)pasteboard
方法。这将让你定义数据的类型和你想要做一个阻力,当穿上纸板什么。如果要禁用拖动完全,你应该能够只返回0(被拖动你想要的项目数)。
其他提示
如果你的目标是 Lion,你可以子类化 IKImageBrowserView
并覆盖 draggingSession:sourceOperationMaskForDraggingContext:
NSDraggingSource 协议 方法。为了防止在应用程序之外拖动,只需返回 NSDragOperationNone
如果上下文是 NSDraggingContextOutsideApplication
. 。否则,返回您感兴趣的拖动操作。这样您就可以禁止拖动到桌面、Finder 等。但仍然允许在应用程序的图像浏览器视图中拖动。
- (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context {
[super draggingSession:session sourceOperationMaskForDraggingContext:context];
switch (context) {
case NSDraggingContextOutsideApplication:
return NSDragOperationNone;
break;
case NSDraggingContextWithinApplication:
return NSDragOperationAll;
break;
default:
return NSDragOperationAll;
break;
}
}
不隶属于 StackOverflow