我了解如何让拖放工作NSCollectionView
但我似乎无法阻止它“将”物品从视图中“抬起”。
我目前的解决方案是not实施
func collectionView(_ collectionView: NSCollectionView, pasteboardWriterForItemAt indexPath: IndexPath) -> NSPasteboardWriting?
from NSCollectionViewDelegate
为了保证
func collectionView(_ collectionView: NSCollectionView, draggingImageForItemsAt indexPaths: Set<IndexPath>, with event: NSEvent, offset dragImageOffset: NSPointPointer) -> NSImage
IS调用,我可以在其中提供我自己的拖动图像。然而,它们不会聚集或提供显示有多少项目被拖动的图标。
问题是,当我实现前一种方法时,我似乎什么也没做(包括覆盖 NSCollectionViewItem 的draggingImageComponents
)似乎可以防止拖动将项目从集合视图中“提起”,从而留下空白空间。
拖动 Photos.app 中的图像和 Finder.app(图标视图)中的文件不会抬起该项目,因此希望这是可能的。
这似乎与以下本质上是同一个问题NSCollectionView - 拖动显示一个“洞” - 希望它看起来像 Finder https://stackoverflow.com/questions/54467265/prevent-nscollectionview-lifting-an-item-during-drag/59893117#59893117
我最初的解决方案是对集合视图项使用自定义视图。在我的子类中我重写setHidden:
以防止在拖动项目时集合视图隐藏我的项目视图。这有一些不良的副作用。看来 NSCollectionView 在更改布局时也会隐藏项目视图。
下一个想法(到目前为止)在我的应用程序中运行良好。当拖动开始时,我取消隐藏项目视图。
@interface HGImagesCollectionViewDelegate : NSObject <NSCollectionViewDelegate>
@end
@implementation HGImagesCollectionViewDelegate
- (void)collectionView:(NSCollectionView *)collectionView
draggingSession:(NSDraggingSession *)session
willBeginAtPoint:(NSPoint)screenPoint
forItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
{
// Prevent item from being hidden (creating a hole in the grid) while being dragged
for (NSIndexPath *indexPath in indexPaths) {
[[[collectionView itemAtIndexPath:indexPath] view] setHidden:NO];
}
// …
}
@end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)