NSTextView, appending text and smooth scrolling
This may help you...
- (void)maybeAutoscrollForThumb:(ThumbImageView *)thumb {autoscrollDistance = 0;// only autoscroll if the thumb is overlapping the thumbScrollViewif (CGRectIntersectsRect([thumb frame], [thumbScrollView bounds])) { CGPoint touchLocation = [thumb convertPoint:[thumb touchLocation] toView:thumbScrollView]; float distanceFromLeftEdge = touchLocation.x - CGRectGetMinX([thumbScrollView bounds]); float distanceFromRightEdge = CGRectGetMaxX([thumbScrollView bounds]) - touchLocation.x; if (distanceFromLeftEdge < AUTOSCROLL_THRESHOLD) { autoscrollDistance = [self autoscrollDistanceForProximityToEdge:distanceFromLeftEdge] * -1; // if scrolling left, distance is negative } else if (distanceFromRightEdge < AUTOSCROLL_THRESHOLD) { autoscrollDistance = [self autoscrollDistanceForProximityToEdge:distanceFromRightEdge]; } }// if no autoscrolling, stop and clear timerif (autoscrollDistance == 0) { [autoscrollTimer invalidate]; autoscrollTimer = nil;} // otherwise create and start timer (if we don't already have a timer going)else if (autoscrollTimer == nil) { autoscrollTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / 60.0) target:self selector:@selector(autoscrollTimerFired:) userInfo:thumb repeats:YES];}
}