How to catch multi-touch event in NSView
Is there any way to handle multi-touch in a class which extend NS开发者_如何学PythonView? currently 1 touch with drag event is working now.
I know this is an old question, but if you want your NSView subclass to accept touch events (like in iOS, touchesBegan/Moved/Ended/Cancelled) and you are in OS X >= 10.6, you can put the following in your initWithFrame: method:
[self setAcceptsTouchEvents:YES];
[self setWantsRestingTouches:YES]; // for thumb
Then override the following methods:
- (void)touchesBeganWithEvent:(NSEvent *)event;
- (void)touchesMovedWithEvent:(NSEvent *)event;
- (void)touchesEndedWithEvent:(NSEvent *)event;
- (void)touchesCancelledWithEvent:(NSEvent *)event;
See the Cocoa Event Handling Guide for details
Actually, I am developing a feature which draw a chart and I used Core-Plot charting library, but the CPLayerHosting is extended from NSView so I don't know how to catch more than one touch points.
Very lucky for me that there are 2 CPLayerHosting class in Core-Plot project, another one is just used for IPhone and it is extended from UIView, so the problem is resolved! :)
精彩评论