简体   繁体   English

如何在iOS上实现多点触控

[英]How do I implement multitouch on iOS

I'd like to implement multitouch, and I was hoping to get some sanity checks from the brilliant folks here. 我想实现多点触控,我希望能从这里的才华横溢的人们那里获得一些理智的检查。 :) :)

From what I can tell, my strategy to detect and track multitouch is going to be to use the touchesBegan _Moved and _Ended methods and use the allTouches method of the event parameter to get visibility on all relevant touches at any particular time. 据我所知,我检测和跟踪多点触摸的策略将是使用touchesBegan _Moved和_Ended方法,并使用事件参数的allTouches方法在任何特定时间获取所有相关触摸的可见性。

I was thinking I'd essentially use the previousLocationInView as a way of linking touches that come in with my new events with the currently active touches, ie if there is a touchBegan for one that is at x,y = 10,14, then I can use the previous location of a touch in the next message to know which one this new touch is tied to as a way of keeping track of one finger's continuous motion etc. Does this make sense? 我在想,我实际上是将previousLocationInView用作将新事件中出现的触摸与当前活动的触摸相关联的一种方法,即如果x,y = 10,14的touchBegan出现了,那么我可以在下一条消息中使用触摸的先前位置来知道此新触摸与哪个触摸相关联,从而可以跟踪一个手指的连续运动等。这有意义吗? If it does make sense, is there a better way to do it? 如果确实可行,还有更好的方法吗? I cannot hold onto UITouch or UIEvent pointers as a way of identifying touches with previous touches, so I cannot go that route. 我无法使用UITouch或UIEvent指针作为通过以前的触摸来识别触摸的方式,因此我无法走这条路。 All I can think to do is tie them together via their previouslocationInView value (and to know which are 'new' touches). 我所能做的就是通过它们的previouslocationInView值将它们联系在一起(并知道哪些是“新的”接触)。

You might want to take a look at gesture recognizers. 您可能需要看一下手势识别器。 From Apple's docs, 根据Apple的文档,

You could implement the touch-event handling code to recognize and handle these gestures, but that code would be complex, possibly buggy, and take some time to write. 您可以实现触摸事件处理代码来识别和处理这些手势,但是该代码很复杂,可能有错误,并且需要花费一些时间来编写。 Alternatively, you could simplify the interpretation and handling of common gestures by using one of the gesture recognizer classes introduced in iOS 3.2. 另外,您可以使用iOS 3.2中引入的一种手势识别器类来简化常见手势的解释和处理。 To use a gesture recognizer, you instantiate it, attach it to the view receiving touches, configure it, and assign it an action selector and a target object. 要使用手势识别器,请实例化它,将其附加到接收触摸的视图上,进行配置,然后为其分配动作选择器和目标对象。 When the gesture recognizer recognizes its gesture, it sends an action message to the target, allowing the target to respond to the gesture. 当手势识别器识别出其手势时,它将动作消息发送到目标,从而使目标能够响应该手势。

See the article on Gesture Recognizers and specifically the section titled "Creating Custom Gesture Recognizers." 请参阅有关手势识别器的文章 ,尤其是标题为“创建自定义手势识别器”的部分。 You will need an Apple Developer Center account to access this. 您将需要一个Apple Developer Center帐户来访问它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM