问题
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.
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]];
Maybe with setBackgroundFilters of NSTextView?
Thanks!
回答1:
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.
}
Moreover, you can use:
self.textview.layoutManager.allowsNonContiguousLayout = YES;
to improve performance slightly.
This is not the same as having an opaque background, but it helps.
来源:https://stackoverflow.com/questions/35728127/transparent-nstextview-performance