Rik*_*Rik 3 cocoa nscollectionview swift
我了解如何进行拖放工作,NSCollectionView
但我似乎无法阻止它“将”项目从视图中“抬起”。
我目前的解决方案是不实施
func collectionView(_ collectionView: NSCollectionView, pasteboardWriterForItemAt indexPath: IndexPath) -> NSPasteboardWriting?
Run Code Online (Sandbox Code Playgroud)
从NSCollectionViewDelegate
确保
func collectionView(_ collectionView: NSCollectionView, draggingImageForItemsAt indexPaths: Set<IndexPath>, with event: NSEvent, offset dragImageOffset: NSPointPointer) -> NSImage
Run Code Online (Sandbox Code Playgroud)
IS被调用,我可以在其中提供我自己的拖动图像。然而,它们不会聚集或提供显示有多少项目被拖动的图标。
问题是,当我实现前一种方法时,我似乎没有做任何事情(包括覆盖 NSCollectionViewItem's draggingImageComponents
)似乎可以阻止拖动将项目从集合视图中“提升”,留下一个空白空间。
拖动 Photos.app 中的图像和 Finder.app(图标视图)中的文件不会抬起该项目,因此希望这是可能的。
这似乎与 NSCollectionView 本质上是相同的问题- 拖动显示 \xe2\x80\x9chole\xe2\x80\x9d - 希望它看起来像 Finder
\n\n我最初的解决方案是对集合视图项使用自定义视图。在我的子类中我重写setHidden:
以防止集合视图在拖动项目时隐藏我的项目视图。这有一些不良的副作用。看来 NSCollectionView 在更改布局时也会隐藏项目视图。
下一个想法(到目前为止)在我的应用程序中运行良好。当拖动开始时,我取消隐藏项目视图。
\n\n@interface HGImagesCollectionViewDelegate : NSObject <NSCollectionViewDelegate>\n\n@end\n\n@implementation HGImagesCollectionViewDelegate\n\n- (void)collectionView:(NSCollectionView *)collectionView\n draggingSession:(NSDraggingSession *)session\n willBeginAtPoint:(NSPoint)screenPoint\n forItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths\n{\n // Prevent item from being hidden (creating a hole in the grid) while being dragged\n for (NSIndexPath *indexPath in indexPaths) {\n [[[collectionView itemAtIndexPath:indexPath] view] setHidden:NO];\n }\n\n // \xe2\x80\xa6\n\n} \n\n@end\n
Run Code Online (Sandbox Code Playgroud)\n
归档时间: |
|
查看次数: |
936 次 |
最近记录: |