我需要将图像从浏览器拖到 mac 应用程序。从 img 标签拖动图像时,它可以正常工作,但是当 img 之间有链接时,它就不起作用了。NSPasteboard 从链接接收 NSURL,而不是从 img 源。拖动反馈显示图像,所以我认为它正在发送图像数据。我从 NSPasteboard 检查了 propertyListForType,它只包含链接 href。
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
if ([sender draggingSource] == nil){
NSPasteboard *pboard = [sender draggingPasteboard];
if ([[pboard types] containsObject:NSURLPboardType]){
NSURL* file = [NSURL URLFromPasteboard: [sender draggingPasteboard]];
//if <img> tag, file is src. If <a><img></a>, it’s link href
//DOWNLOAD image here
}
}
}