Skip to content

Instantly share code, notes, and snippets.

@stuartjmoore
Created July 28, 2012 22:20
Show Gist options
  • Save stuartjmoore/3195007 to your computer and use it in GitHub Desktop.
Save stuartjmoore/3195007 to your computer and use it in GitHub Desktop.
NSScrollView - scrollViewDidBeginScrolling & scrollViewDidEndScrolling
// When you init your view
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(scrollViewDidScroll:) name:NSViewBoundsDidChangeNotification object:scrollView.contentView];
// The methods
- (void)scrollViewDidBeginScrolling
{
// Do stuff
}
- (void)scrollViewDidScroll:(NSNotification*)notification
{
if(scrollTimer == nil)
[self scrollViewDidBeginScrolling];
// Do stuff
if (scrollTimer != nil && [scrollTimer isValid])
[scrollTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
else
scrollTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(scrollViewDidEndScrolling) userInfo:nil repeats:NO];
}
- (void)scrollViewDidEndScrolling
{
// Do stuff
if(scrollTimer != nil)
scrollTimer = nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment