10

I have done quite a bit with gesture recognizers for iOS, but I am now doing work in OS X, and I am lost.

I want to duplicate the functionality that exists like in Finder where you can two-finger swipe (on your magic mouse) to go back/forward through a directory tree.

I have an NSWindow based app that looks very similar to Finder. I have used apps before that allows you to build your own gesture recognizers so I know it is possible to do it, but I don't see any documentation on it.

What do I need to do to implement these gestures?

Westley
  • 1,143
  • 14
  • 27

3 Answers3

4

Mac now has:

  • NSClickGestureRecognizer
  • NSMagnificationGestureRecognizer
  • NSPanGestureRecognizer
  • NSPressGestureRecognizer
  • NSRotationGestureRecognizer

Available in storyboards too.

Rudolf Adamkovič
  • 31,030
  • 13
  • 103
  • 118
2

You can read about Handling Trackpad Events in the Cocoa Event Handling guide. The system can detect some pre-defined gestures (swipe, rotate, etc.) or you can listen to the raw touch events, which travel up the NSResponder chain, just like regular mouse events.

Морт
  • 1,163
  • 9
  • 18
0

Looks like there is also an Event Recognizer class in CZKit. https://github.com/CarterA/CZKit

I haven't used this (yet), so YMMV.

livingtech
  • 3,570
  • 29
  • 42
  • Couldn't find anything related to gestures in that lib. – Sentry.co Apr 23 '16 at 08:40
  • I still haven't used it, and from the README can't even remember what it's supposed to do, but I assume I was referring to the `CZActionRecognizer` class in this directory: https://github.com/CarterA/CZKit/tree/master/Libraries/CZUI/Classes It looks like that is supposed to be a base class for general gesture/actions. Looks like you'll need to write any actual recognizers yourself though, unless you just want to recognize clicks. Good luck! – livingtech Apr 25 '16 at 06:09
  • Its a general event handler for a potential Gesture event? Thats the best interpretation I can make. Could be contextual important to someone I guess. Thumbs up for the effort to explain. :) As a note to others that are looking for information related to gesture events: What i've found is that there are two approaches. One is to override gesture methods in the NSView. The other and more modern approach is to add "Selectors" to Gesture recognizers. The later provides better control over when the gesture began and ended etc. Although the same can be achieved by overriding. Just not as easily. – Sentry.co Apr 25 '16 at 13:18