Search code examples
objective-ccocoanavigationmagic-mouseswipe-gesture

How to implement the two-finger swipe gesture in Cocoa to go back and forward?


Several applications like Safari and the Finder go back and forward when you swipe with two fingers on your Magic Mouse (or with three fingers on your Magic Trackpad).

How would I implement this in my Cocoa application? What classes are available?


Solution

  • Three finger swipes are easiest, because NSResponder already does the work for you:

    - (void)swipeWithEvent:(NSEvent *)event;
    

    If you want to support two finger swipes (which I don't think technically can be classified as swipes, but rather scroll gestures), you'll have to manually process the touches- see http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/EventOverview/HandlingTouchEvents/HandlingTouchEvents.html#//apple_ref/doc/uid/10000060i-CH13-SW10