如何在NSView中捕捉多点触摸事件

问题描述:

有什么办法来处理扩展NSView的类中的多点触摸?目前与拖动事件的1触摸正在工作。如何在NSView中捕捉多点触摸事件

+0

我有延长的NSView类,并在这个类,我可以捕获mouseDown,mouseUp,mouseDragged事件,但我不知道如何计算屏幕上的触摸次数,如果有可能,我可以将它作为多点触摸事件来处理。任何人都可以帮助我! – 2010-06-29 02:54:03

我知道这是一个老问题,但如果你想让你的NSView子类接受触摸事件(比如在iOS中,touchesBegan/Moved/Ended/Canceled)并且你在OS X> = 10.6中,你可以把你的initWithFrame如下:方法:

[self setAcceptsTouchEvents:YES]; 
[self setWantsRestingTouches:YES]; // for thumb 

然后覆盖下面的方法:

- (void)touchesBeganWithEvent:(NSEvent *)event; 
- (void)touchesMovedWithEvent:(NSEvent *)event; 
- (void)touchesEndedWithEvent:(NSEvent *)event; 
- (void)touchesCancelledWithEvent:(NSEvent *)event; 

Cocoa Event Handling Guide的细节

+0

如果可能,请帮我解决我的问题。 [这里](http://*.com/questions/24734940/disable-user-interaction-for-nsimageview)是问题,非常感谢:) – 2014-07-14 13:39:09

实际上,我正在开发一个绘制图表的功能,我使用了Core-Plot图表库,但CPLayerHosting是从NSView扩展的,因此我不知道如何捕捉多个触摸点。

对我来说非常幸运,Core-Plot项目中有2个CPLayerHosting类,另一个仅用于iPhone,它是从UIView扩展的,所以问题解决了! :)