'How can I disable horizontal scrolling for an NSScrollView?
I first tried disabled the scroll bar by setting:
scrollView!.hasHorizontalScroller = false
and that successfully worked, but I could still scroll from left to right by using my trackpad. Is there a way to ensure that horizontal scrolling is completely disabled for an NSScrollView object?
Solution 1:[1]
Even with a correct content size, I was still able to use two-finger gestures to scroll horizontally a bit before it snaps back into place. To fix this, you can set the elasticity:
scrollView.horizontalScrollElasticity = .None
Solution 2:[2]
In addition to @mikepj's answer I also needed to do the following. Modifying this to become:
override func scrollWheel(with event: NSEvent) {
super.scrollWheel(with: event)
if event.deltaX != 0 {
super.nextResponder?.scrollWheel(with: event)
}
}
This may be because I was using an NSRulerView.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mikepj |
| Solution 2 |
