Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can NSScrollView scroll if setHasHorizontalScroller:NO?

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

like image 976
NuBee Avatar asked May 17 '11 13:05

NuBee


2 Answers

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;
}
like image 87
YoonHo Avatar answered Nov 12 '22 00:11

YoonHo


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://stackoverflow.com/a/12960795/836263

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];
like image 21
Andrew Avatar answered Nov 12 '22 01:11

Andrew