2
我有一个面板上有一个图像,我想让它可以复制一个文件(不是图像,图像只会作为一个服务器通过将应用程序外部的图像“拖动”到任何其他接受拖入其中的文件的应用程序(例如Finder),将该文件的图标拖到文件夹中。我怎样才能做到这一点?可可OSX:我怎样才能使图像拖动
我实现了NSDraggingSource协议,但我不确定如何使图像可拖动。它目前在ImageView
之内,它位于ImageViewCell
之内。
这里是我实现的协议:
#import "DragNDropView.h"
@implementation
-(NSDragOperation)draggingSession:(NSDraggingSession *)session
sourceOperationMaskForDraggingContext: (NSDraggingContext) context{
switch(context){
case NSDraggingContextOutsideApplication:
return NSDragOperationCopy;
break;
default:
return NSDragOperationNone;
break;
}
}
-(void) draggingSession:(NSDraggingSession *)session willBeginAtPoint:(NSPoint) screenPoint{
NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
NSPaseBoardItem *contents = [[NSPasteboardItem alloc]
inithWithPasteboardPreopertyList:SDKFileName ofType:NSFileContentsPboardType];
[pboard writeObjects[NSArray arrayWithObjects:contents, nil]];
}
-(void)drawRect:(NSRect)dirtyRect{
SDKFileName = @"example.example";
[super drawRect:dirtyRect];
}
@end