【问题标题】:Multiple touch problem using UITouch/UIView in iphone在 iphone 中使用 UITouch/UIView 的多点触控问题
【发布时间】:2010-05-30 09:55:18
【问题描述】:

我正在尝试使用 iPhone 3G 和 SDK 3.1.2 在 UIView 上实现 2 指“捏”和“展开”(或放大)。我之前没有在 UITouch/UIEvent 中进行过编程,所以我很感激任何关于我所面临问题的指导。

当我用 2 根手指触摸屏幕时,我发现有时“touchesBegan”只会给我 1 个事件。我需要 UITouch 事件计数 == 2 来测量两根手指之间的距离。

因此我必须抬起手指并再次重复此过程,直到我的两个手指都被检测到。有办法吗?我可以改进它吗? 一旦检测到两个手指,实际调整大小就可以正常工作,但需要解决开始时看到的这个问题。

我知道 SDK 3.2 可以检测到捏合等手势,但我想知道在 3.1.2 中如何实现?

代码如下。即使我放下两根手指,“OnFingerDown”函数也会随机调用,而我希望每次都调用“onTwoFingersDown”。此外,每次我放下手指时,我只会得到 1 个触摸事件。我的意思是,如果“OnFingerDown”被调用了两次,我就能以某种方式让它工作。

提前致谢。感谢任何帮助。

约翰

 - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event

{

     UITouch* touch, *touch1;
     CGPoint location, location1;
     if([[event allTouches] count] == 1) {

               touch=[UI[[event allTouches] allObjects] objectAtIndex:0];
               location=[touch locationInView:self];
               OnFingerDown(location);
     }
     else if([[event allTouches] count] == 2) {

          touch=[[[event allTouches] allObjects] objectAtIndex:0];
          location=[touch locationInView:self];
          touch1=[[[event allTouches] allObjects] objectAtIndex:1];
          location1=[touch1 locationInView:self];

          OnTwoFingersDown(location, location1);

     }

}

【问题讨论】:

    标签: iphone


    【解决方案1】:

    TouchesBegan 仅针对每个事件调用一次。两个同时触摸是一个事件。变量 NSSet* Touches 实际上是同时进行的一组触摸。你必须遍历它们来处理它们。

    UIEvent *event 捆绑当前时刻对视图的所有触摸。包括 NSSet *Touches。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多