我有一个基本的绘图应用程序。我决定让CALayer支持NSView,因为据我所知,Layer Backed Views具有性能优势。此外,我注意到它在实时窗口调整大小期间负责重绘窗口。无论哪种方式,它听起来像双赢。这是我的drawRect:方法,由mouseDragged:
等引发- (void)drawRect:(NSRect)rect
{
if (firstDraw) { //Sets the background to white
[[NSColor whiteColor]set];
NSRectFill(rect);
firstDraw = NO;
}
//strokeDict contains all the variable settings needed to stroke the path.
[(NSColor *)([self->strokeDict objectForKey:@"lineColor"]) set];
NSBezierPath *strokingPath = [[self->strokeDict objectForKey:@"bezierPath"] copy];
[strokingPath setLineWidth:[[self->strokeDict objectForKey:@"lineWidth"]floatValue]];
//setupPath sets the lineJoinStyle & Cap
[setupPath(strokingPath) stroke];
}
然而,在运行时,我得到如下所示的结果(虽然快得多)。到底是怎么回事?