Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Mac OS X Cocoa events for multitouch gestures

I'm writing a program that has an NSView embedded in an NSScrollView which user can zoom. I'd love to set it up so the user can zoom the view using the multitouch pinch gesture supported on MacBook Air and the new unibody MacBooks/MacBooks Pro and in applications like Safari and iPhoto. I've hunted through Apple's documentation and can't figure out how do to this.

  1. Is this supported using publicly available APIs on Mac OS X 10.5 Leopard?
  2. If not, how "bad" are the private APIs (e.g. is it just an undeclared constant or a whole new set of methods)?
like image 634
Alex Avatar asked Dec 18 '22 09:12

Alex


1 Answers

Edit: Snow Leopard adds supported APIs for gestures and multi-touch. See the AppKit release notes for Snow Leopard; ⌘F for “gesture” and “MultiTouch” (sic). They'll look pretty familiar if you've used ones below, but there probably are some fine differences, so read the new documentation anyway.


Is this supported using publicly available APIs on Mac OS X 10.5 Leopard?

No. 10.5.0 doesn't support it at all, and 10.5.1 through 10.5.6 make you implement undocumented methods.

If not, how "bad" are the private APIs (e.g. is it just an undeclared constant or a whole new set of methods)?

Not bad at all. You have to implement some undocumented event methods in your view. Since you're the one implementing the methods, you shouldn't crash if Apple changes the methods; all that will happen is the feature will stop working.

However, if you'll be retrieving the absolute (not delta) magnification or rotation from the event, then those are as-yet-undocumented methods of the event, so you should guard those messages with respondsToSelector: messages and perform careful range-checking on the methods' return values.

like image 99
Peter Hosey Avatar answered Dec 19 '22 22:12

Peter Hosey