Reputation: 445
My app has an NSCollectionView with only one row. I want to make it scroll horizontally with the mouse wheel, but don't want to press the shift button at the same time.
So how can I convert the scrolling direction with AppKit on macOS
Upvotes: 2
Views: 997
Reputation: 66
You can subclass NSCollectionView and override 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)
}
}
}
you can have a try, hope this can help you!
Upvotes: 4