检测iphone上的特殊触摸 [英] Detecting Special touch on the iphone
问题描述
我问自己是否有在线示例,其中包括如何检测触摸手势中的形状。
例如矩形或圆形复杂的心...)
或确定滑动速度(随着时间的推移,我正在刷我的iPhone对50英里每小时))
我问自己是否有在线示例,其中包括如何检测触摸手势中的形状。
例如矩形或圆形复杂的心...)
或确定滑动速度(随着时间的推移,我正在刷我的iPhone对50英里每小时))
对于非常简单的手势(水平或垂直滑动),计算两次触摸之间的x和y之差。
dy = abs(y2 - y1)
dx = abs(x2 - x1)
f = dy / dx
接近零的水平滑动。接近1的f是对角滑动。一个非常大的f是一个垂直滑动(请记住,dx可能为零,因此上面的内容不会为所有x和y产生有效的结果)。
如果你对速度感兴趣,pythagoras可以帮助。两次触摸之间移动的距离长度为:
l = sqrt(dx * dx + dy * dy)
如果触摸发生在时间t1和t2,速度为:
tdiff = abs(t2 - t1)
s = l / tdiff
由你决定哪个值可以解释为快或慢。
您可以扩展这种方法以获得更复杂的图形,例如您的正方形可以是水平/垂直/水平/垂直滑动,其中前一次滑动已停止的开始/结束点。
对于更复杂的数字,具有理想化的形状。可以考虑多边形形状作为理想,并检查是否触摸范围
p>您可以从那里进一步细化。
I was asking myself if there are examples online which covers how you can for instance detect shapes in touch gestures.
for example a rectangle or a circle (or more complex a heart .. )
or determine the speed of swiping (over time ( like i'm swiping my iphone against 50mph ))
For very simple gestures (horizontal vs. vertical swipe), calculate the difference in x and y between two touches.
dy = abs(y2 - y1)
dx = abs(x2 - x1)
f = dy/dx
An f close to zero is a horizontal swipe. An f close to 1 is a diagonal swipe. And a very large f is a vertical swipe (keep in mind that dx could be zero, so the above won't yield valid results for all x and y).
If you're interested in speed, pythagoras can help. The length of the distance travelled between two touches is:
l = sqrt(dx*dx + dy*dy)
If the touches happened at times t1 and t2, the speed is:
tdiff = abs(t2 - t1)
s = l/tdiff
It's up to you to determine which value of s you interpret as fast or slow.
You can extend this approach for more complex figures, e.g. your square shape could be a horizontal/vertical/horizontal/vertical swipe with start/end points where the previous swipe stopped.
For more complex figures, it's probably better to work with an idealized shape. One could consider a polygon shape as the ideal, and check if a range of touches
You can refine things further from there.
这篇关于检测iphone上的特殊触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!