【问题标题】:NSImageView drag and drop still works outside window boundariesNSImageView 拖放在窗口边界外仍然有效
【发布时间】:2015-02-10 21:56:56
【问题描述】:

我有一个NSImageView,拖放连接如下:

-(NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender{

    if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
        == NSDragOperationGeneric) {

        return NSDragOperationGeneric;

    } // end if

    // not a drag we can use
    return NSDragOperationNone;
}


-(NSDragOperation) draggingUpdated:(id<NSDraggingInfo>)sender{

    return NSDragOperationCopy;
}

-(void) draggingEnded:(id<NSDraggingInfo>)sender{

    NSPasteboard *pboard = [sender draggingPasteboard];

    if ( [[pboard types] containsObject:NSFilenamesPboardType] )
    {
        NSArray *files = [pboard
              propertyListForType:NSFilenamesPboardType];

        // Loop through all the files and process them.
        for( int i = 0; i < [files count]; i++ )
        {
             ....
        }
}

这一切都很好。从 Finder 中拖动文件时,如果在视图内部,则表示加号,在外部则删除加号。它还指示要在一个小气泡中复制多少文件。所有这些都很好。但是,如果我将视图拖到应用程序之外,则加号会消失,但在释放时它仍会​​将文件放入视图中。我怎样才能阻止这种行为?

非常感谢您的任何想法。

【问题讨论】:

    标签: objective-c drag-and-drop nsimageview


    【解决方案1】:

    我想我已经找到了解决办法。

    我没有使用draggingEnded,而是使用performDragOperation,一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-04
      • 2023-04-04
      • 2011-06-27
      • 1970-01-01
      • 2011-07-18
      • 2022-11-25
      相关资源
      最近更新 更多