几周来,我一直在努力解决多点触控“手指跟踪”问题。我的背景是硬件和嵌入式系统编程,所以我对微 Controller 编程以外的任何事情都没有经验。我取得了一些成功,但前提是多个触摸同时开始和结束。我的项目是音频硬件的手势控制界面,因此我需要跟踪每次触摸以生成自定义手势。
这个例子展示了我如何从 [touches allObjects] 中提取每个触摸以便单独处理它们(我排除了处理代码,它对这个例子来说是多余的)
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
touchesArray = [touches allObjects]; //Array Declared in header to hold multiple touches.
NSUInteger nNumTouches = [touchesArray count]; //Counts number of touches in Array
UITouch *touch = [touches anyObject];
CGPoint ptTouch;
for (int nTouch = 0; nTouch < nNumTouches; nTouch++)
{
touch = [touchesArray objectAtIndex:nTouch];
ptTouch = [touch locationInView:self.view];
{
是否有更有效的方法来跟踪每次触摸?我觉得我的编程知识已经走到尽头了。特别是在尝试操作 NSMutable 数组无效之后。我也读过,但未能从这里执行详细信息:https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/multitouch_background/multitouch_background.html#//apple_ref/doc/uid/TP40009541-CH5-SW9
对此的回应看起来很有趣,但我无法让它在上下文中工作:
how to track multitouch events on iphone?
感谢您的宝贵时间,我们将不胜感激,
汤姆。
最佳答案
接受的答案是正确的。但是,对于那些仍然没有弄清楚如何实现这个想法的人,请看我的回答here .
基本概念是在调用 touchesBegan::
时将每个 UITouch ID 存储在一个数组中,然后将每个 ID 与 touchesMoved::
中屏幕上的触摸进行比较事件。这样,每个手指都可以与单个对象配对,并在平移时进行跟踪。
关于ios - 跟踪 iPhone 上的多次触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21610438/