Created
July 28, 2012 22:20
-
-
Save stuartjmoore/3195007 to your computer and use it in GitHub Desktop.
NSScrollView - scrollViewDidBeginScrolling & scrollViewDidEndScrolling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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