I'm having a problem with custom drawing NSView using as documentView of a NSScrollView.
Here is my drawRect: code:
- (void)drawRect:(NSRect)dirtyRect
{
[[NSColor lightGrayColor] set];
NSRectFill(self.frame); // Fill entire frame
[[NSColor grayColor] set];
[NSBezierPath setDefaultLineWidth:1];
float y = 0.0f;
while (y <= self.frame.size.height) {
[NSBezierPath strokeLineFromPoint:NSMakePoint(0.0f, y) toPoint:NSMakePoint(self.frame.size.width, y)];
y += 50.0f;
}
float x = 0.0f;
while (x <= self.frame.size.width) {
[NSBezierPath strokeLineFromPoint:NSMakePoint(x, 0.0f) toPoint:NSMakePoint(x, self.frame.size.height)];
x += 50.0f;
}
}
Everything is OK when I scroll the view rightward, but I see strange lines when I scroll the view leftward.
I think this is a cached image buffer or something but I couldn't get why this occurs because I fill a rect which covers entire frame.
What causes this problem? How can I solve it? Thanks.