Transparent NSTextView performance

北城以北 提交于 2019-12-11 10:56:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!