Objective c Cocoa OSX:如何使图像可拖动
我有一个面板,上面有一个图像,我想制作一个面板,这样你就可以通过将图像“拖动”到应用程序之外的文件夹中,并将文件(而不是图像,图像仅作为文件的图标发送到服务器)复制到一个文件夹中,以及将文件拖到其中的任何其他应用程序中(例如Finder)。我该怎么做 我实现了协议,但我不确定如何使图像可拖动。它当前位于Objective c Cocoa OSX:如何使图像可拖动,objective-c,xcode,cocoa,Objective C,Xcode,Cocoa,我有一个面板,上面有一个图像,我想制作一个面板,这样你就可以通过将图像“拖动”到应用程序之外的文件夹中,并将文件(而不是图像,图像仅作为文件的图标发送到服务器)复制到一个文件夹中,以及将文件拖到其中的任何其他应用程序中(例如Finder)。我该怎么做 我实现了协议,但我不确定如何使图像可拖动。它当前位于图像视图的内部,该视图位于图像视图单元格的内部 以下是我实施的协议: #import "DragNDropView.h" @implementation -(NSDragOperation)d
图像视图
的内部,该视图位于图像视图单元格
的内部
以下是我实施的协议:
#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
我添加了方法
-(id)initWithCoder(NSCode*)coder
,并且还添加了-(BOOL)acceptesFirstMouse:(NSEvent*)事件{return YES;}