Can NSScrollView scroll if setHasHorizontalScroller: NO?

Is it possible to "hide" NSScrollView scrollers and still have gestural scroll behavior?

+7
source share
5 answers

Subclass NSScroller and set it as the vertical / horizontal scroller for the NSScrollView instance.

A subclass of NSScroller should override this (10.7 and above):

+ (CGFloat)scrollerWidthForControlSize:(NSControlSize)controlSize scrollerStyle:(NSScrollerStyle)scrollerStyle { return 0; } 
+4
source

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

1) NSScroller subclass (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 at https://stackoverflow.com/a/167168/

2) Rollback and momentum seem to be broken when using an outdated style. It also partially breaks Apple code scrolling sync . This causes the scroll to scroll to reset the scroll position if it is NSScrollerStyleOverlay and the other is NSScrollerStyleLegacy . If the scroll scroll in the overlay style scrolls, the old style scrolls, it resets both types of scroll to the top scroll offset y = 0.

 [self.scrollView setHasVerticalScroller:YES]; [self.scrollView setScrollerStyle:NSScrollerStyleLegacy]; [self.scrollView setHasVerticalScroller:NO]; 
+3
source

It makes scrollview not display the scroller and not respond to strict scrolling:

 -setHasHorizontalScroller:NO 

Causes the disabled scroller to appear, but it responds to strict scrolling:

 -setHasHorizontalScroller:YES -setHidden:YES 
+1
source

Yes it is possible. Try this shortly after initializing scrollView.

  self.scrollView.wantsLayer = YES; 

I got this to work without hiding the subclass of NSScroller and not touching setHasVerticalScroller: Also, if self.scrollView is a subclass that overrides drawRect: try disabling it to make sure that what you do there does not cause a problem.

+1
source

Why don't you just give it a try?

To answer the question: Yes, if the user has a mouse with a scroll wheel or a touchpad with a scroll, you can still scroll the view, despite the invisibility of the scroll.

0
source

All Articles