How can I disable vertical scrolling of NSScrollView?
You can observe the offset of the content in scrollViewDidScroll: and set the x value to the value you want.
Edit: Ok then. Have you seen this: Scrolling constraint ?
source to share
Try this in a subclass of NSScrollView:
- (void)scrollWheel:(NSEvent *)theEvent
{
[super scrollWheel:theEvent];
if ([theEvent deltaY] != 0.0)
{
[[self nextResponder] scrollWheel:theEvent];
}
}
Also you can do this:
NSLog(@"user scrolled %f horizontally and %f vertically", [theEvent deltaX], [theEvent deltaY]);
source to share
I like the way Ivan answers above. However, in my particular case, I had a table view (vertical scrolling) where each row contained a collection view (horizontal scrolling).
When users tried to scroll up / down, if the mouse hovered over one of the collection views, they could not scroll up or down.
To solve this problem, I subclassed NSScrollView containing NSCollectionViews and I overridden this method with the following code:
override func scrollWheel(with event: NSEvent)
{
if (fabs(Double(event.deltaY)) > fabs(Double(event.deltaX))) {
self.nextResponder?.scrollWheel(with: event);
} else {
super.scrollWheel(with: event);
}
}
Thus, it checks if the user is predominantly scrolling in one direction and handles it accordingly.
source to share