如何检测鼠标/手指是否沿着特定路径移动?
我正在为 iPhone 开发一个应用程序,我想检测用户何时沿着特定路径移动手指。
具体来说,我想检测用户何时沿着特定的圆形路径移动手指。
这可能很容易通过检测鼠标沿路径的运动来适应。
I'm developing an application for iPhone, and I want to detect when the user is moving his finger along a certain path.
Specifically, I want to detect when the user moves their finger along a specific circular path.
This would probably be easily adapted from detecting mouse motion along a path.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
似乎特定案例的实施起来相当简单。 将输入区域分为四个象限并跟踪每个象限的位置。 象限的顺序决定了它们是否已经完成或绕了一圈。
描述这个想法的伪代码:
这个想法是你只需要粗略地识别一个区域的特定触摸。 所以象限例程会是这样的:
我使用象限作为例子 - 显然你可以画一个正方形并认为“圆形!”。 通过在 Detect 方法中创建更多区域来提高准确性。 主要思想是根据区域序列进行思考,以便实现所需的行为,而不会过度复杂化(如贝塞尔曲线检测或类似的废话)。 这个伪代码肯定是粗暴的,我确信有一个很好的方法来巧妙地实现。 我一直在为我正在从事的一个项目考虑“圆周运动检测”,这是我想出的粗略想法。
享受!
Seems like a specific case can be fairly simple to implement. Divide the input area into four quadrants and track the position through each quadrant. The sequence of quandrants determines if they have completed or traveled in a circle.
Pseudo-code to describe the idea:
The idea is that you only need to roughly identify a particular touch to a region. So the quadrant routine would something like this:
I use quadrants as an example - clearly you could draw a square and think 'circle!'. The accuracy is improved by making more regions in the Detect method. The main idea is to think in terms of sequences of regions in order to achieve the desired behavior without excessive complication (like bezier curve detection or similar nonsense). This pseudo code is certainly brutish and I'm sure there's a nice way to finesse the implementation. I've been thinking about 'circular motion detection' for a project I'm working on and this was the rough idea I came up with.
Enjoy!
由于我对 iPhone SDK 本身不熟悉,所以我不确定是否有内置的用于捕获非标准手势的工具。 但是,这是您可以执行此操作的手动方法之一。
本教程适用于 Flash,但其操作原理相同。 每个方向代表一个数字。 使用定点设备画一个圆圈将生成一系列数字,代表随时间或距离移动的方向,这取决于您。 将该数字序列与表示圆的预定义序列进行比较。 如果它们匹配,则触发一个事件。
有很多教程解释了如何制作这样的“模糊”手势,以便需要不太精确的点运动。
Since I'm not familiar with the iPhone SDK itself, I'm not sure if there are built in facilities for capturing non-standard gestures. However, here is one of the manual ways you can do it.
This tutorial is for Flash, but it operates on the same gesture principles. Each direction represents a number. Tracing a circle with the pointing device will generate a sequence of numbers representing the directions travelled either over time or over distance, its up to you. Compare that sequence of numbers to a pre-defined sequence representing a circle. If they match, fire an event.
There are plenty of tutorials that explain how to make gestures like this "fuzzy" so that less precise point motion is required.