2013-05-09 91 views
1

我有一个NSTextView和这里的滚动条的正常大小:
enter image description here
这里就是发生在我悬停的TextView的滚动条:
enter image description here
不过,我不希望有这样的“扩大'效应。我怎样才能删除它?我试图搜索如何执行此操作,但我找不到任何东西。我只是想要一直使用普通的卷轴大小(即更薄的大小),即使用户使用它。这可能吗?
谢谢如何在NSTextView的NSScrollView滚轮上禁用鼠标悬停展开效果?

+0

你为什么要强迫你的用户提供不断所谓薄的iOS风格的滚动条,这是很难打,用鼠标指针乱动?!我真的希望这不是“美学”! – 2013-05-15 20:24:41

回答

2

我建议子类NSScroller和覆盖– drawArrow:highlight:/– drawKnobSlotInRect:highlight:/– drawKnob方法,让你有一个稳定的滚动条的外观。

P.S.不要忘记在XIB文件中为滚动条设置新的滚动条类。

UPDATE

下面是示例代码:

- (void)drawKnob 
{ 
    // call the default implementation for Overlay Scrollers 
    if (self.scrollerStyle == NSScrollerStyleOverlay) 
    { 
     [super drawKnob]; 
     return; 
    } 

    if (_style == NSScrollerKnobStyleLight || _style == NSScrollerKnobStyleDefault) 
      [[NSColor colorWithCalibratedWhite:1.0 alpha:0.8] setFill]; 
    else [[NSColor colorWithCalibratedWhite:0 alpha:0.4] setFill]; 

    // Note: you can specify the rect with fixed width here 
    NSRect knobRect = [self rectForPart:NSScrollerKnob]; 

    // VERTICAL SCROLLER 
    NSInteger fullWidth = knobRect.size.width; 
    knobRect.size.width = round(knobRect.size.width/2); 
    knobRect.origin.x += (NSInteger)((fullWidth - knobRect.size.width)/2); 

    // draw... 
    NSBezierPath * thePath = [NSBezierPath bezierPath]; 

    [thePath appendBezierPathWithRoundedRect:knobRect xRadius:4 yRadius:4]; 
    [thePath fill]; 
} 

//--------------------------------------------------------------- 

- (void)drawKnobSlotInRect:(NSRect)slotRect highlight:(BOOL)flag 
{ 
    // call the default implementation for Overlay Scrollers 
    // draw nothing for usual 
    if (self.scrollerStyle == NSScrollerStyleOverlay) 
    { 
     [super drawKnobSlotInRect:slotRect highlight:flag]; 
    } 
} 

//--------------------------------------------------------------- 

- (void)drawArrow:(NSScrollerArrow)whichArrow highlight:(BOOL)flag 
{ 
    // call the default implementation for Overlay Scrollers 
    // draw nothing for usual 
    if (self.scrollerStyle == NSScrollerStyleOverlay) 
    { 
     [super drawArrow:whichArrow highlight:flag]; 
    } 
} 
+0

您能否更具体地在这些方法的内部做些什么?我已经玩过这些方法,我有点了,但滚动只是不离开(鼠标)滚动条后隐藏 – 2013-05-14 17:08:52

+1

我更新了我的答案与示例代码。是的,非叠加滚动条不会隐藏,但始终存在。如果你想模拟iOS的滚动器行为,也许你应该寻找像https://github.com/rheinfabrik/RFOverlayScrollView – UJey 2013-05-14 18:44:45

0

我不知道你想要什么确切的风格,但这个类别可能会帮助你。

@implementation NSScrollView (SetScrollStyle) 

- (void) setHidingScroll 
{ 
    [self setScrollerStyle:NSScrollerStyleOverlay]; 
    [[self verticalScroller] setControlSize: NSSmallControlSize]; 
    [[self verticalScroller] setKnobStyle:NSScrollerKnobStyleDark]; 
    [self setScrollerKnobStyle:NSScrollerKnobStyleDark]; 
    [[self verticalScroller] setScrollerStyle:NSScrollerStyleOverlay]; 
} 

和使用

[scrollView setHidingScroll]; 
+0

感谢您的回答,但是当我将鼠标悬停在滚动条上时,效果仍然存在 – 2013-05-13 09:52:48