title: NSScrollView and manually setting the content offset while scrolling
body: <p>I am trying to build an endless NSScrollView, i.e. a scroll view that can scroll infinitely in either direction. This is achieved by having a scroll view with fixed dimension which is 'recentered' once it gets too close to either edge, and keeping track of an additional endless offset that is updated when recentering. Apple even demonstrated this approach in a WWDC video for iOS, if I recall correctly.</p>
  
  <p>On iOS everything is working. I perform the recentering logic in <code>-scrollViewDidScroll:</code> and it even works when the scrolling motion is decelerating without breaking the deceleration.</p>
  
  <p>Now for the Mac version. Let me tell you that I'm fairly new to Mac development, so I may simply not have performed these operations in the correct places. I currently have the recentering logic in <code>-reflectScrolledClipView:</code>. When I perform the move operation immediately, however, the scroll view jumps exactly twice as far as I want it to (in this case, to 4000). If I delay the method slightly, it works just as expected.</p>
  
  <pre><code>- (void)reflectScrolledClipView:(NSClipView *)cView
  {
      [self recenteringLogic];
      [super reflectScrolledClipView:cView];
  }
  
  - (void)recenteringLogic
  {
      CGFloat offset = self.documentVisibleRect.origin.y;
  
      if (offset &gt; 6000) {
  
          // This makes the scroll view jump to ~4000 instead of 5000.
          [self performSelector:@selector(move) withObject:nil];
  
          // This works, but seems wrong to me
  //        [self performSelector:@selector(move) withObject:nil afterDelay:0.0];
      }
  }
  
  - (void)move
  {
      [self.documentView scrollPoint:NSMakePoint(0, 4000)];
  }
  </code></pre>
  
  <p>Any ideas on how I could achieve the behavior I want?</p>