![](/img/trans.png)
[英]Horizontal NSCollectionView in vertical NSTableView does not select until collection view is clicked
[英]Horizontal NSCollectionView in vertically scrolling NSTableView Swift macOS
我创建了一个垂直滚动的 NSTableView。 这个表视图的每个单元格都包含一个标题,下面是一个水平滚动的 NSCollectionView。 当滚动时光标位于标题上时,垂直 tableview 滚动得很好,但是当光标位于水平滚动的 collection view 上时,table view 不会滚动。
即使光标位于集合视图上,如何让表视图滚动? 我知道tableview和scrollview使用两个独立的滚动视图,但是不知道有没有办法同步这两个。
好的,感谢上帝,毕竟我在 stackoverflow 上找到了解决方案。 它是在 Objective-C 中的,所以我将它翻译成 Swift。 这是针对任何正在寻找类似问题的人:
class MTHorizontalScrollView: NSScrollView {
var currentScrollIsHorizontal = false
override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
}
override func scrollWheel(with event: NSEvent) {
if event.phase == NSEvent.Phase.began || (event.phase == NSEvent.Phase.ended && event.momentumPhase == NSEvent.Phase.ended) {
currentScrollIsHorizontal = fabs(event.scrollingDeltaX) > fabs(event.scrollingDeltaY)
}
if currentScrollIsHorizontal {
super.scrollWheel(with: event)
} else {
self.nextResponder?.scrollWheel(with: event)
}
}
}
完全归功于SO LINK
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.