我有一个自定义集合视图:
import AppKit
final class InternalCollectionView: NSCollectionView {
typealias KeyDownHandler = (_ event: NSEvent) -> Bool
var keyDownHandler: KeyDownHandler? = nil
// Do nothing on Cmd+A
override func selectAll(_ sender: Any?) { }
}
我还有 SwiftUI 的 collectionView,里面使用了一些控制器:
struct FBCollectionView<Content: View>: NSViewControllerRepresentable {
//here some implementation
}
public class NSCollectionController<Content: View>: NSViewController, NSCollectionViewDelegate, NSCollectionViewDataSource, QLPreviewPanelDataSource, QLPreviewPanelDelegate {
//here some implementation
}
我需要实现逻辑:
首先,我试图在拖动开始时隐藏应用程序。为此,我已经实施了
NSCollectionController
的方法:
public func collectionView(_ collectionView: NSCollectionView, draggingSession session: NSDraggingSession, willBeginAt screenPoint: NSPoint, forItemsAt indexPaths: Set<IndexPath>) {
hideApp()
preventHidingItemsDuringDrag(collectionView, indexPaths: indexPaths)
}
func hideApp() {
DispatchQueue.main.async {
NSApplication.shared.hide(self)
}
appShown = false
automaticScroller.updStatus(appDisplayed: appShown)
}
但出于某种原因,这仅适用于第一次拖动(!)在每个后续拖动应用程序不会隐藏
我试图在主线程中运行这段代码,但没有得到任何可用的结果
所以问题是: