我有WebView其中我加载webarchive的内容。在相同的看法我有IKImageView插座。图像从Web视图拖放到图像视图不适用于我。来自WebView的图像拖动到IKImageView
什么是奇怪的,它适用于我拖动照片例如从iPhoto到相同的图像视图。 此外,我可以从我的网络视图拖动图像到NSScrollView(它创建一个链接到图像),我可以拖动相同的照片到一个新的邮件消息(按预期创建一个图像)。
IKImageView在IB中启用了“支持拖放”功能。
我在这里错过了什么?
我有WebView其中我加载webarchive的内容。在相同的看法我有IKImageView插座。图像从Web视图拖放到图像视图不适用于我。来自WebView的图像拖动到IKImageView
什么是奇怪的,它适用于我拖动照片例如从iPhoto到相同的图像视图。 此外,我可以从我的网络视图拖动图像到NSScrollView(它创建一个链接到图像),我可以拖动相同的照片到一个新的邮件消息(按预期创建一个图像)。
IKImageView在IB中启用了“支持拖放”功能。
我在这里错过了什么?
事实证明,在我的情况下处理死亡的最好方法是通过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;
}
IKImageView
很可能是在等待NSFilenamesPboardType
的粘贴板,webview如何处理拖动图像?
“图片来自网络视图中拖动n个墨滴到图像视图不为我工作”请更具体。会发生什么呢? – 2009-12-18 23:25:51
我可以拖动图像(转向缩略图并被遮挡),但悬停在IKImageView上不会将光标切换到带有绿色加号的光标,并释放鼠标按钮会导致我的拖动图像“返回”到网页视图(到原始图像的地方)。 – 2009-12-19 10:59:50