Mac cocoa - how can i detect trackpad scroll gestures?

Erik Sapir picture Erik Sapir · Jul 10, 2011 · Viewed 10.8k times · Source

I want to detect scroll gestures (two fingers on trackpad). How should i do that?

Answer

spudwaffle picture spudwaffle · Jul 10, 2011

Looks like you want to override your view's scrollWheel: method. You can use the NSEvent's deltaX and deltaY methods to get how much the user has scrolled by.

Code:

@implementation MyView

- (void)scrollWheel:(NSEvent *)theEvent {
    NSLog(@"user scrolled %f horizontally and %f vertically", [theEvent deltaX], [theEvent deltaY]);
}

@end

You also may want to take a look at the Handling Trackpad Events Guide. This will show you how to capture custom gestures, in addition to standard ones.