默认情况下(看起来),IKImageBrowserView 允许拖放到 Finder 中的位置。我想关闭此行为,但不确定如何操作。我在想也许实现 NSDraggingDestination 协议并覆盖它可以解决这个问题,但到目前为止它对我没有用。
谢谢你的帮助!
默认情况下(看起来),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;
}
}