我正在尝试创建一个拖动视图,您可以在其中拖动应用程序生成的文件。这是一个子类,NSImageView
到目前为止我已经编写了这个方法:
- (void)mouseDown:(NSEvent *)pTheEvent {
NSPoint tvarMouseInWindow = [pTheEvent locationInWindow];
NSPoint tvarMouseInView = [self convertPoint:tvarMouseInWindow fromView:nil];
NSSize zDragOffset = NSMakeSize(0, 0);
NSPasteboard *zPasteBoard;
zPasteBoard = [NSPasteboard pasteboardWithName:NSDragPboard];
[zPasteBoard declareTypes:[NSArray arrayWithObject:NSTIFFPboardType] owner:self];
[zPasteBoard setData:[[self image] TIFFRepresentation] forType:NSTIFFPboardType];
[self dragImage:[self image] at:tvarMouseInView offset:zDragOffset event:pTheEvent pasteboard:zPasteBoard source:self slideBack:YES];
return;
}
当我现在将包含的图像从 imageView 中拖出并尝试将其放入 Finder 窗口时,它只是向后滑动并且不会复制。如何NSView
正确实现文件拖动(而不是拖放!)区域?