Can NSScrollView scroll if setHasHorizontalScroller:NO?
Asked Answered
T

5

7

Is it possible to 'hide' the scrollers of an NSScrollView and still get gestural scrolling behavior?

Terylene answered 17/5, 2011 at 13:36 Comment(0)
M
4

Create an NSScroller subclass and set it as the vertical/horizontal scroller for the NSScrollView instance.

The NSScroller subclass should override this (10.7 and above):

+ (CGFloat)scrollerWidthForControlSize:(NSControlSize)controlSize scrollerStyle:(NSScrollerStyle)scrollerStyle {
return 0;
}
Madaras answered 3/10, 2012 at 21:53 Comment(0)
S
3

This is definitely a bug in AppKit. I was able to get this working on 10.8.5 using either of the following solutions:

1) Subclass NSScroller (preferred method)

+ (BOOL)isCompatibleWithOverlayScrollers
{
    // Let this scroller sit on top of the content view, rather than next to it.
    return YES;
}

- (void)setHidden:(BOOL)flag
{
    // Ugly hack: make sure we are always hidden.
    [super setHidden:YES];
}

Source: jmk in https://mcmap.net/q/1017160/-synchronize-two-nsscrollview

2) Bounce-back and momentum seems broken when using the legacy style. It also partially breaks Apple's scroll synchronization code. It causes the scroll views to reset scroll position if one is NSScrollerStyleOverlay and the other is NSScrollerStyleLegacy. If the overlay-style scroll view is scrolled, then the legacy style is scrolled, it resets both scroll views to the top y=0 scroll offset.

[self.scrollView setHasVerticalScroller:YES];
[self.scrollView setScrollerStyle:NSScrollerStyleLegacy];
[self.scrollView setHasVerticalScroller:NO];
Sunglasses answered 28/9, 2013 at 0:20 Comment(0)
S
1

Causes the scrollview to not display a scroller and not respond to gestural scrolling:

-setHasHorizontalScroller:NO

Causes a disabled scroller to be displayed, but it responds to gestural scrolling:

-setHasHorizontalScroller:YES
-setHidden:YES
Sollows answered 22/7, 2011 at 23:18 Comment(1)
I think maybe you mean "YES causes a disabled scroller NOT to be displayed, but it responds to gestural scrolling", no?Hebron
T
1

Yes, it is possible. Try this soon after initializing the scrollView.

    self.scrollView.wantsLayer = YES;

I've gotten this to work without hiding an NSScroller subclass and without touching setHasVerticalScroller:. Also, if self.scrollView is a subclass that overrides drawRect:, try turning that off to make sure that what you're doing there isn't causing the problem.

Thinskinned answered 8/7, 2014 at 3:38 Comment(0)
S
0

Why don't you just try it?

To answer the question: Yes, if the user has mouse with a scroll wheel or a a scrolling-capable touchpad, it is still possible to scroll the view, despite the scrollers being invisible.

Soupspoon answered 17/5, 2011 at 14:4 Comment(1)
Not sure what I'm doing wrong. I can scroll with my trackpad when setHasHorizontalScroller:YES, but not if setHasHorizontalScroller:NO.Terylene

© 2022 - 2024 — McMap. All rights reserved.