How can I disable vertical scrolling of NSScrollView?

How can I disable vertical scrolling of NSScrollView?

I cannot find a quick google solution.

thank

+3


source to share


4 answers


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 ?

0


source


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]);

      

+4


source


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.

0


source


was wondering if you ran into

- (void)setHasVerticalScroller:(BOOL)flag;

      

to disable vertical scrollbar?

You can also set this in the Interface Builder.

-7


source







All Articles