Skip to content

Instantly share code, notes, and snippets.

@ktakayama
Created April 23, 2011 03:57
Show Gist options
  • Save ktakayama/938252 to your computer and use it in GitHub Desktop.
Save ktakayama/938252 to your computer and use it in GitHub Desktop.
@interface NSScrollView (swipe)
- (void) scrollToTop;
- (void) scrollToBottom;
@end
static const CGFloat kSwipeGestureUp = 1.0;
static const CGFloat kSwipeGestureDown = -1.0;
@implementation NSScrollView (swipe)
- (void) swipeWithEvent:(NSEvent *)event {
if([event deltaY] == kSwipeGestureUp) {
[self scrollToTop];
} else if([event deltaY] == kSwipeGestureDown) {
[self scrollToBottom];
}
}
- (void) scrollToTop {
CGFloat y = 0.0;
if(![self.documentView isFlipped]) {
y = NSMaxY([self.documentView frame]) - NSHeight([self.contentView bounds]);
}
[self.documentView scrollPoint:NSMakePoint(0.0, y)];
}
- (void) scrollToBottom {
CGFloat y = 0.0;
if([self.documentView isFlipped]) {
y = NSMaxY([self.documentView frame]) - NSHeight([self.contentView bounds]);
}
[self.documentView scrollPoint:NSMakePoint(0.0, y)];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment