我有一个具有半透明背景的基于视图的NSTableView。这很好,除了在行动画期间。如果我对NSTableView背景使用完全不透明的颜色,那么就没有问题了.下面是一个显示问题的gif:
http://gfycat.com/ChillyVigorousChamois
正如gif所显示的,在动画期间,背景闪烁着比它应有的更深的红色。如果仔细观察,实际上有一个正确绘制的背景部分,它向下滑动以容纳新添加的行。
NSScrollView后面的NSTableView是纯白色的,如下代码所设置的:
-(void) awakeFromNib {
self.drawsBackground = YES;
self.backgroundColor = [NSColor whiteColor];
}NSTableView具有50%的透明红色背景,如下代码所示:
-(BOOL) isOpaque {
return NO;
}
- (void)drawBackgroundInClipRect:(NSRect)clipRect {
[[[NSColor redColor] colorWithAlphaComponent:0.5] setFill];
NSRectFillUsingOperation(clipRect, NSCompositeSourceOver);
}行是用以下代码动画化的:
[_tableView insertRowsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:insertRange]
withAnimation:NSTableViewAnimationSlideLeft];我目前最好的猜测是,由于背景在动画过程中被反复地画在顶部,所以会出现变暗。在过去,我通过将父视图添加到NSAnimation中来修复类似的错误,这迫使它与动画的子视图一起被反复重新绘制。在这种情况下,我不知道如何做同样的事情。
有什么办法解决这个问题吗?
发布于 2014-08-20 01:00:31
这并不能真正解决这个问题,但这里有一个解决办法。诀窍是将整个NSScrollView放入自定义NSView中,并在自定义NSView中绘制背景。
使NSTableView透明:
@implementation SJTableView
- (BOOL)isOpaque {
return NO;
}
-(void) drawBackgroundInClipRect:(NSRect)clipRect {
NSRectFillUsingOperation(clipRect, NSCompositeClear);
}
@end使NSScrollView透明:
_scrollView.drawsBackground = NO;在自定义视图中绘制背景:
@implementation SJView
-(BOOL) isOpaque {
return (_backgroundColor.alphaComponent >= 1.0);
}
-(void) drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
if(_backgroundColor){
[_backgroundColor setFill];
NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver);
}
}
@endhttps://stackoverflow.com/questions/25377717
复制相似问题