首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于视图的NSOutlineView中的查找器样式的浮动分组行

基于视图的NSOutlineView中的查找器样式的浮动分组行
EN

Stack Overflow用户
提问于 2012-01-04 08:56:19
回答 1查看 1.4K关注 0票数 2

我在我的项目中实现了一个基于视图的NSOutlineView。我使用的是浮动组行。现在,我希望这个NSOutlineView看起来基本上像查找器列表视图(CMD-2),当它处于“按种类”布局时(例如,"by kind":CTRL-CMD-2)。这意味着,最上面的组行应该显示列标题,一旦下一个组行开始将前一个组行移出视图,列标题就会在第二个组行上淡入(我希望这是有意义的)。

有没有什么开箱即用的方法来实现这一点?到目前为止,我已经成功地将NSTableCellView子类化以显示列的标题,但是,我无法使淡入起作用,因为我似乎找不到分组行相对于它上面浮动行的位置。

问候你,迈克尔

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-09 09:16:45

我已经找到了一种可能的方法来实现我想要的。在我定制的NSTableCellView的drawRect:方法中,当然可能是以一种糟糕的方式来找出视图相对于封闭的NSClipView的位置。相关代码:

代码语言:javascript
复制
- (void)drawRect:(NSRect)dirtyRect {
  // _isGroupView is a member variable which has to be set previously
  // (usually in setObjectValue:) in order for us to know if we're a 
  // group row or not.
  if (_isGroupView) {

    // This is the nasty party:
    NSClipView *clipView = (NSClipView*)self.superview.superview.superview;
    if (![clipView isKindOfClass:[NSClipView class]]) {
      NSLog(@"Error: something is wrong with the scrollbar view hierarchy.");
      return;
    }

    NSRect clipRect = [clipView documentVisibleRect];
    CGFloat distanceToTop = self.superview.frame.origin.y - clipRect.origin.y;
    if (self.superview.frame.origin.y - clipRect.origin.y < self.frame.size.height) {
      // This means, that this NSTableCellView is currently pushing the
      // view above it out of the frame.

      CGFloat alpha = distanceToTop / self.frame.size.height;
      NSColor *blendColor = [[NSColor blackColor] blendedColorWithFraction:alpha    ofColor:[NSColor whiteColor]];

      // ...
      // do stuff with blendColor
      // ...
      // blendColor should now be the appropriate color for the wanted 
      // "fade in" effect.
      // 
    }
  }
}

我希望这是有意义的;-)。任何建议都是非常感谢的!

干杯,迈克尔

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8720795

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档