我的应用程序有一个只有一行的 NSCollectionView。我想让它用鼠标滚轮水平滚动,但不想同时按下shift按钮。
那么如何在 macOS 上使用 AppKit 转换滚动方向
最佳答案
您可以继承 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)
}
}
}
你可以尝试一下,希望对你有帮助!
关于swift - 如何在 macOS 上使用 AppKit 使鼠标滚轮水平滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65001621/