我在我的项目中实现了一个基于视图的NSOutlineView。我使用的是浮动组行。现在,我希望这个NSOutlineView看起来基本上像查找器列表视图(CMD-2),当它处于“按种类”布局时(例如,"by kind":CTRL-CMD-2)。这意味着,最上面的组行应该显示列标题,一旦下一个组行开始将前一个组行移出视图,列标题就会在第二个组行上淡入(我希望这是有意义的)。
有没有什么开箱即用的方法来实现这一点?到目前为止,我已经成功地将NSTableCellView子类化以显示列的标题,但是,我无法使淡入起作用,因为我似乎找不到分组行相对于它上面浮动行的位置。
问候你,迈克尔
发布于 2012-01-09 09:16:45
我已经找到了一种可能的方法来实现我想要的。在我定制的NSTableCellView的drawRect:方法中,当然可能是以一种糟糕的方式来找出视图相对于封闭的NSClipView的位置。相关代码:
- (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.
//
}
}
}我希望这是有意义的;-)。任何建议都是非常感谢的!
干杯,迈克尔
https://stackoverflow.com/questions/8720795
复制相似问题