我的应用程序有一个只有一行的NSCollectionView。我想让它水平滚动与鼠标轮,但不想在同一时间按下移位按钮。
那么如何用AppKit在macOS上转换滚动方向呢?
发布于 2020-11-30 07:36:50
您可以子类NSCollectionView和重写scrollWheel。
import Cocoa
class YourCollectionView: NSCollectionView {
override func scrollWheel(with event: NSEvent) {
// get mouse wheel scroll offset
let scrollOffset = event.scrollingDeltaY
// scroll collectionView your self, maybe like this
if let clipView = self.enclosingScrollView?.contentView as? NSClipView {
let currentPoint = self.visibleRect.origin
let newPoint = CGPoint(x: currentPoint.x + scrollOffset ,y: currentPoint.y)
clipView.scroll(to: newPoint)
}
}
}
你可以试试,希望这能帮到你!
https://stackoverflow.com/questions/65001621
复制相似问题