防止NSCollectionView在拖动过程中“举起”项目

问题描述 投票:2回答:1

我知道如何为NSCollectionView拖放,但似乎无法阻止它“将”项目从视图中“抬起”。

我当前的解决方案是not实施

func collectionView(_ collectionView: NSCollectionView, pasteboardWriterForItemAt indexPath: IndexPath) -> NSPasteboardWriting?

NSCollectionViewDelegate以确保

func collectionView(_ collectionView: NSCollectionView, draggingImageForItemsAt indexPaths: Set<IndexPath>, with event: NSEvent, offset dragImageOffset: NSPointPointer) -> NSImage

IS称为,我可以在其中提供自己的拖动图像。但是,这些不会聚集或提供显示要拖动多少个项目的图标。

问题是,当我实现前一种方法时,我似乎无所事事(包括覆盖NSCollectionViewItem的draggingImageComponents)似乎阻止了将项目从集合视图中“拖动”出来,从而留下了空白。

拖曳Photos.app中的图像和Finder.app中的文件(图标视图)不会抬起该项目,因此希望可以这样做。

swift cocoa nscollectionview
1个回答
0
投票

这似乎与NSCollectionView - dragging shows a “hole” - want it to look like the Finder基本上是相同的问题

我的解决方案是对集合视图项使用自定义视图。在我的子类中,我重写setHidden:以防止在拖动项目时集合视图隐藏我的项目视图。

@interface HGImagesCollectionViewItemView : NSView

@end


@implementation HGImagesCollectionViewItemView

- (void)setHidden:(BOOL)hidden
{
//  Prevent item from being hidden (creating a hole in the grid) while being dragged
//  [super setHidden:hidden];
}

@end
© www.soinside.com 2019 - 2024. All rights reserved.