11

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?

ra1nmaster
  • 662
  • 1
  • 8
  • 21

3 Answers3

6

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
mikepj
  • 1,256
  • 11
  • 11
0

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.

Patrick
  • 2,035
  • 17
  • 27
-5
var scrollView = UIScrollView(frame:myFrame)
let scroll = CGSizeMake(myHeight, myFrame.size.width)
scrollView.contentSize = scroll

Fixes the frame width to prevent horizontal scrolling.

Steve Rosenberg
  • 19,348
  • 7
  • 46
  • 53