How can I implement gesture recognizers in OS X?

2020-07-06 03:07发布

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?

3条回答
\"骚年 ilove
2楼-- · 2020-07-06 03:26

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

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

查看更多
一夜七次
3楼-- · 2020-07-06 03:37

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.

查看更多
疯言疯语
4楼-- · 2020-07-06 03:41

Mac now has:

  • NSClickGestureRecognizer
  • NSMagnificationGestureRecognizer
  • NSPanGestureRecognizer
  • NSPressGestureRecognizer
  • NSRotationGestureRecognizer

Available in storyboards too.

查看更多
登录 后发表回答