透明的NSTextView性能 [英] Transparent NSTextView performance
问题描述
我有一个带有NSImage的NSWindow和上面带有长文本的NSTextView http://www.gutenberg.org/cache/epub/100/pg100.txt ,如果我使用纯色背景绘画,则文本编辑会很快.
I have a NSWindow with a NSImage and a NSTextView above it with a long text http://www.gutenberg.org/cache/epub/100/pg100.txt and if I draw with a solid background, the text editing is fast.
但是,如果我没有背景绘制,则[self setDrawsBackground:NO]
会非常慢.
But if I draw with no background, [self setDrawsBackground:NO]
it's very slow.
有任何更新吗?我也尝试过
Any updates? I have also tried
[self setDrawsBackground:YES];
[self setBackgroundColor:[NSColor clearColor]];
也许使用NSTextView的setBackgroundFilters?
Maybe with setBackgroundFilters of NSTextView?
谢谢!
推荐答案
我找到了部分解决方案.如果禁用字体的平滑处理,则性能会提高很多. 首先,您必须具有NSTextView的子类. 然后,
I found a partial solution. If you disable the smoothed of the font, the performance improves a lot. First you must have a subclass of NSTextView. Then,
- (void)drawRect:(NSRect)dirtyRect
{
[[NSGraphicsContext currentContext] setShouldAntialias:YES];
CGContextSetShouldAntialias((CGContextRef)[[NSGraphicsContext currentContext] graphicsPort], YES);
CGContextSetShouldSmoothFonts((CGContextRef)[[NSGraphicsContext currentContext] graphicsPort], NO);
[super drawRect:dirtyRect];
// Drawing code here.
}
此外,您可以使用:
self.textview.layoutManager.allowsNonContiguousLayout = YES;
稍微改善性能.
这与具有不透明的背景不同,但有帮助.
This is not the same as having an opaque background, but it helps.
这篇关于透明的NSTextView性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!