title: custom drawing nsview inside nsscrollview
body: <p>I'm having a problem with custom drawing NSView using as documentView of a NSScrollView.</p>
  
  <p>Here is my drawRect: code:</p>
  
  <pre><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 &lt;= 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 &lt;= self.frame.size.width) {
          [NSBezierPath strokeLineFromPoint:NSMakePoint(x, 0.0f) toPoint:NSMakePoint(x, self.frame.size.height)];
          x += 50.0f;
      }
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/s8k1K.png" alt="Drawing a grid"></p>
  
  <p>Everything is OK when I scroll the view rightward, but I see strange lines when I scroll the view leftward.</p>
  
  <p><img src="https://i.stack.imgur.com/59Tlm.png" alt="enter image description here"></p>
  
  <p>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.</p>
  
  <p>What causes this problem? How can I solve it? Thanks.</p>