Skip to content

Instantly share code, notes, and snippets.

@danwood
Created December 23, 2011 04:03
Show Gist options
  • Save danwood/1513093 to your computer and use it in GitHub Desktop.
Save danwood/1513093 to your computer and use it in GitHub Desktop.
Scroll the the bottom if you are at the bottom
- (void) scrollToVisible:(id)unused
{
// Only show bottom if we are already scrolled down at/near the bottom.
NSScrollView *scrollView = [oLog enclosingScrollView];
NSPoint currentScrollPosition=[[scrollView contentView] bounds].origin;
float diff = oLog.frame.size.height - (scrollView.contentSize.height + currentScrollPosition.y);
if (diff < 50) // Seems like it's often 39 when we're at the bottom, so give some slack.
{
// [oLog scrollRangeToVisible:NSMakeRange([[oLog textStorage] length], 0)];
// Below might be better:
[scrollView.contentView scrollToPoint:NSMakePoint(0, oLog.frame.size.height - scrollView.contentSize.height)];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment