如何在 iOS 上实现多点触控

发布于 2024-09-28 13:27:01 字数 439 浏览 1 评论 0原文

我想实现多点触控,并且希望能从这里的杰出人士那里得到一些健全性检查。 :)

据我所知,我检测和跟踪多点触摸的策略将是使用 TouchBegan _Moved 和 _Ended 方法,并使用事件参数的 allTouches 方法来获取任何特定时间所有相关触摸的可见性。

我想我本质上会使用 previousLocationInView 作为将新事件中的触摸与当前活动触摸链接起来的一种方式,即,如果 x,y = 10,14 处有一个 touchBegan,那么我可以使用下一条消息中触摸的前一个位置来了解该新触摸与哪一个触摸相关,作为跟踪一根手指的连续运动等的一种方式。这有意义吗?如果确实有意义,是否有更好的方法?我无法保留 UITouch 或 UIEvent 指针作为识别触摸与先前触摸的方式,所以我不能走那条路。我能想到的就是通过它们 previouslocationInView 值将它们联系在一起(并知道哪些是“新”触摸)。

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.

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, i.e. 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? 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. All I can think to do is tie them together via their previouslocationInView value (and to know which are 'new' touches).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〃温暖了心ぐ 2024-10-05 13:27:01

您可能想看看手势识别器。从苹果的文档来看,

您可以实现触摸事件处理代码来识别和处理这些手势,但该代码会很复杂,可能有错误,并且需要一些时间来编写。或者,您可以使用 iOS 3.2 中引入的手势识别器类之一来简化常见手势的解释和处理。要使用手势识别器,您需要实例化它,将其附加到接收触摸的视图,配置它,并为其分配操作选择器和目标对象。当手势识别器识别出其手势时,它会向目标发送一条动作消息,允许目标响应该手势。

请参阅 关于手势识别器的文章,特别是标题为“创建自定义手势识别器”的部分。您需要一个 Apple 开发人员中心帐户才能访问此帐户。

You might want to take a look at gesture recognizers. From Apple's docs,

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. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文