Created
April 23, 2011 03:57
-
-
Save ktakayama/938252 to your computer and use it in GitHub Desktop.
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
@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