Search code examples
objective-cmacosnsscrollview

NSScrollView disable autoscrolling


How do I disable the autoscroll in a NSScrollView as I'm filling it with content?

I have subclassed it in my own class but I don't find an appropriate method to override.


Solution

  • There's probably more than one way to go about this, but take a look at -[NSClipView constrainScrollPoint:]. It's not meant to be called directly, rather to be overridden in an NSClipView subclass. NSClipView is the class that actually does the real work of scrolling the content of an NSScrollView.

    You should be able to override it to simply return the document view's current origin point when you don't want scrolling to happen. It's worth noting that this will also disable scrolling via the user-visible interface, so you should only do it while you're filling the view with content. Otherwise, return the result of a call to the superclass's implementation.