2011-12-22 48 views
5

的顶部和底部我在寻找一种方式来画上一个表视图淡入淡出效果(和大纲视图,但我认为这将是相同的),当滚动内容。下面是从Fantastical应用的例子:淡出效果在NSTableView的/ NSOutlineView

fade effect on top

另外一个类似的淡入的上QuickLook的窗口here的视频。


为了这个,我试着子类一的tableview的滚动视图使用此代码:

#define kFadeEffectHeight 15 

@implementation FadingScrollView 

- (void)drawRect: (NSRect)dirtyRect 
{ 
    [super drawRect: dirtyRect]; 

    NSGradient* g = [[NSGradient alloc] initWithStartingColor: [NSColor blackColor] endingColor: [NSColor clearColor]]; 

    NSRect topRect = self.bounds; 
    topRect.origin.y = self.bounds.size.height - kFadeEffectHeight; 
    topRect.size.height = kFadeEffectHeight; 

    NSRect botRect = self.bounds; 
    botRect.size.height = kFadeEffectHeight; 

    [NSGraphicsContext saveGraphicsState]; 
    [[NSGraphicsContext currentContext] setCompositingOperation: NSCompositeDestinationAtop]; 
    // Tried every compositing operation and none worked. Please specify wich one I should use if you do it this way 

    [g drawInRect: topRect angle: 90]; 
    [g drawInRect: botRect angle: 270]; 

    [NSGraphicsContext restoreGraphicsState]; 
} 

...但是这并没有什么褪色,可能是因为这是实际的表视图之前调用画了。我对如何做到这一点:(

顺便说一句,无论是tableview中,我想有这种效果的outlineview不知道是基于视图,应用程序是只10.7。

+0

可以为您提供的效果,或者你鼓舞人心上的应用程序的iTunes的链接视频? – viggio24 2011-12-22 12:48:07

+0

@ viggio24在应用商店中添加了Fantastical的链接,并在另一个示例中添加了视频 – Alex 2011-12-22 13:33:52

回答

7

在Mac OS X(因为你的问题被标记了),有几个陷阱让这很难,尤其是对于有弹性滚动的狮子,

我已经(就在今天)把我认为是比工作更好的方法直接使用表格或大纲视图:自定义的NSScrollView子类,它可以将两个“淡入淡出视图”平铺在剪辑视图顶部的正确位置。JLNFadingScrollView可以配置所需的淡入淡出高度和颜色,并且是自由/开源的Github上。请尊重许可并享受。 :-)

Examples of JLNFadingScrollView