2010-06-13 49 views
4

默認情況下(看起來),IKImageBrowserView可以拖放到Finder中的位置。我想關閉此行爲,但不確定如何操作。我在想,也許實現NSDraggingDestination協議並覆蓋它可以解決這個問題,但到目前爲止它還沒有爲我工作。刪除IKImageBrowserView的拖放行爲

感謝您的幫助!

+0

'NSDraggingDestination'協議正是它說的:它是作爲拖拽*目的地*的協議。在視圖類中實現它或覆蓋它不會改變任何有關從*拖動*的事情;當用戶這樣做時,視圖就是drag * source *。 – 2010-06-14 07:57:04

回答

6

如果要定製IKImageBrowserView的拖放行爲,可以在瀏覽器的數據源對象中實現- (NSUInteger) imageBrowser:(IKImageBrowserView *) aBrowser writeItemsAtIndexes:(NSIndexSet *) itemIndexes toPasteboard:(NSPasteboard *)pasteboard方法。這樣可以讓您在拖動時定義要放在粘貼板上的類型和數據。如果你想完全禁止拖動,你應該能夠返回0(你想要拖動的項目的數量)。

1

如果您的目標是Lion,您可以繼承IKImageBrowserView並覆蓋draggingSession:sourceOperationMaskForDraggingContext:NSDraggingSource protocol方法。如果上下文爲NSDraggingContextOutsideApplication,爲了防止應用程序之外的拖動只返回NSDragOperationNone。否則,返回您感興趣的拖動操作。這樣,您可以禁止拖動到桌面,Finder等,但仍允許在應用程序的圖像瀏覽器視圖中拖動拖動操作。

- (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context { 
    [super draggingSession:session sourceOperationMaskForDraggingContext:context]; 

    switch (context) { 
     case NSDraggingContextOutsideApplication: 
      return NSDragOperationNone; 
      break; 

     case NSDraggingContextWithinApplication: 
      return NSDragOperationAll; 
      break; 

     default: 
      return NSDragOperationAll; 
      break; 
    } 
}