2009-12-18 49 views
1

我有WebView其中我加載webarchive的內容。在相同的看法我有IKImageView插座。圖像從Web視圖拖放到圖像視圖不適用於我。來自WebView的圖像拖動到IKImageView

什麼是奇怪的,它適用於我拖動照片例如從iPhoto到相同的圖像視圖。 此外,我可以從我的網絡視圖拖動圖像到NSScrollView(它創建一個鏈接到圖像),我可以拖動相同的照片到一個新的郵件消息(按預期創建一個圖像)。

IKImageView在IB中啓用了「支持拖放」功能。

我在這裏錯過了什麼?

+0

「圖片來自網絡視圖中拖動n個墨滴到圖像視圖不爲我工作」請更具體。會發生什麼呢? – 2009-12-18 23:25:51

+0

我可以拖動圖像(轉向縮略圖並被遮擋),但懸停在IKImageView上不會將光標切換到帶有綠色加號的光標,並釋放鼠標按鈕會導致我的拖動圖像「返回」到網頁視圖(到原始圖像的地方)。 – 2009-12-19 10:59:50

回答

0

事實證明,在我的情況下處理死亡的最好方法是通過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; 
} 
1

IKImageView很可能是在等待NSFilenamesPboardType的粘貼板,webview如何處理拖動圖像?