如何像这样为 NSTableCellView 拖放
How to make a drag & drop for NSTableCellView like this
我正在尝试为 NSTableCellView
实现拖放,看起来像屏幕截图,但我唯一能做的就是文本,而不是像下面的屏幕截图那样的整个单元格:(
The Dragged Image
The image that is dragged in a dragging session is simply an image
that represents the data on the pasteboard. Although a dragging
destination can access the image, its primary concern is with the
pasteboard data that the image represents—the dragging operation that
a destination ultimately performs is on the pasteboard data, not on
the image itself.
见Custom drag image with NSTableView as drag source
这是我对问题的回答:)
NSView 到 NSImage:link
覆盖 NSTableCellView
子类中的 draggingImageComponents
-(NSArray *) draggingImageComponents{
self.layer.opacity = 0.5;
NSImage *image = [self imageRepresentation];
self.layer.opacity = 1;
NSDraggingImageComponent *draggingImage = [NSDraggingImageComponent draggingImageComponentWithKey:@"background"];
draggingImage.contents = image;
draggingImage.frame = self.bounds;
return @[draggingImage];
}
我正在尝试为 NSTableCellView
实现拖放,看起来像屏幕截图,但我唯一能做的就是文本,而不是像下面的屏幕截图那样的整个单元格:(
The Dragged Image
The image that is dragged in a dragging session is simply an image that represents the data on the pasteboard. Although a dragging destination can access the image, its primary concern is with the pasteboard data that the image represents—the dragging operation that a destination ultimately performs is on the pasteboard data, not on the image itself.
见Custom drag image with NSTableView as drag source
这是我对问题的回答:)
NSView 到 NSImage:link
覆盖 NSTableCellView
子类中的 draggingImageComponents
-(NSArray *) draggingImageComponents{
self.layer.opacity = 0.5;
NSImage *image = [self imageRepresentation];
self.layer.opacity = 1;
NSDraggingImageComponent *draggingImage = [NSDraggingImageComponent draggingImageComponentWithKey:@"background"];
draggingImage.contents = image;
draggingImage.frame = self.bounds;
return @[draggingImage];
}