9

我正在寻找一次在屏幕上检测多个手指的最佳方法。我没有检测到轻敲或捏合,只是发生了不止一次触摸的事实。似乎没有任何手势识别器。最好的方法是什么?

4

5 回答 5

14

在 touchesBegan、touchesMoved 和 touchesEnded 方法中,一个参数是 event,它是一个 UIEvent 对象。屏幕上的手指数为 [[event allTouches]count]。

[已编辑,因为 Josh Hinman 指出我之前做错了——我之前在这些相同方法中对 touches 参数使用 [touches count] 的建议将不起作用。]

于 2010-09-30T18:52:14.600 回答
4

阅读-touchesBegan:withEvent:方法。它是多点触控事件处理的入口点。

这是关于多点触控事件的开发人员库链接: https ://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/MultitouchEvents/MultitouchEvents.html

于 2010-09-30T17:55:33.837 回答
1
  • (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    NSLog(@"%lu",[[event allTouches] count]); }

于 2016-11-11T13:15:09.773 回答
0

单点/多点触控对您来说是透明的 - 您只会收到有关触控开始/移动/结束/点击的位置的通知。如果同时发生两次触摸,您将收到两者的通知。

我不知道有任何内置函数可以确定您看到的触摸序列是否包含捏合 - 但您可以查看 Apple 的“触摸”示例代码以获得灵感。

https://developer.apple.com/library/ios/#samplecode/Touches/

于 2010-09-30T17:54:58.580 回答
0

您可以尝试使用 UITapGestureRecognizer 类,并将numberOfTouchesRequired属性设置为 2。

请注意,这仅在视图上的multipleTouchEnabled设置为 YES 时才有效。

于 2010-09-30T17:57:05.080 回答