我有WebView,在这里我加载了webarchive的内容。在同样的观点中,我有IKImageView插座。从web视图拖到图像视图上的图像拖放对我不起作用。
奇怪的是,当我将照片(例如从iPhoto )拖到相同的图像视图上时,它可以工作。此外,我还可以将图像从我的web视图拖到NSScrollView上(这会创建到图像的链接),我还可以将同一张照片拖到新邮件上(按预期创建图像)。
IKImageView在IB中启用了“支持拖放”。
我在这里错过了什么?
发布于 2010-01-16 13:12:55
事实证明,在我的情况下,最好的处理方式是通过WebArchivePboardType。然后:
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPasteboard *pboard;
NSDragOperation sourceDragMask;
sourceDragMask = [sender draggingSourceOperationMask];
pboard = [sender draggingPasteboard];
// Create image data from webarchive stored in a pasteboard.
NSData *image = [pboard dataForType:WebArchivePboardType];
WebArchive *webArchive = [[WebArchive alloc] initWithData:image];
// Let's see what are we dragging.
for (WebResource *subresource in [webArchive subresources])
{
NSString *mimeType = [subresource MIMEType];
if ([mimeType hasPrefix:expectedMimeTypeStartsWith])
{
NSData *data = [subresource data];
CFDataRef imgData = (CFDataRef)data;
CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData (imgData);
CGImageRef image;
if ([mimeType hasSuffix:@"png"])
{
image = CGImageCreateWithPNGDataProvider(imgDataProvider, NULL, true, kCGRenderingIntentDefault);
}
else if ([mimeType hasSuffix:@"jpeg"])
{
image = CGImageCreateWithJPEGDataProvider(imgDataProvider, NULL, true, kCGRenderingIntentDefault);
}
[self setImage:image imageProperties:nil];
}
}
return YES;
}发布于 2009-12-18 20:08:27
IKImageView可能正在期待一个NSFilenamesPboardType的贴图板,webview是如何处理拖动图像的呢?
https://stackoverflow.com/questions/1928011
复制相似问题