Two-finger rotation gesture on the iPhone?

那年仲夏 提交于 2019-12-03 00:51:03

I've done that before by finding the previous and current distances between the two fingers, and the angle between the previous and current lines. Then I picked some empirical thresholds for that distance delta and angle theta, and that has worked out pretty well for me.

If the distance was greater than my threshold, and the angle was less than my threshold, I scaled the image. Otherwise I rotated it. 2 finger scroll seems easy to distinguish.

BTW in case you are actually storing the values, the touches have previous point values already stored.

CGPoint previousPoint1 = [self scalePoint:[touch1 previousLocationInView:nil]];
CGPoint previousPoint2 = [self scalePoint:[touch2 previousLocationInView:nil]];
CGPoint currentPoint1 = [self scalePoint:[touch1 locationInView:nil]];
CGPoint currentPoint2 = [self scalePoint:[touch2 locationInView:nil]];

Two fingers, both moving, opposit(ish) directions. What gesture conflicts with this?

Pinch/zoom I guess comes close, but whereas pinch/zoom will start off moving away from a center point (if you trace backwards from each line, your lines will be parallel and close), rotate will initially have parallel lines (tracing backwards) that will be far away from each other and those lines will constantly change slope (while retaining distance).

edit: You know--both of these could be solved with the same algorithm.

Rather than calculating lines, calculate the pixel under each finger. If the fingers move, translate the image so that the two initial pixels are still under the two fingers.

This solves all two-finger actions including scroll.

Two-finger scroll or Zoom might look a little wobbly at times since it will do other operations as well, but this is how the map app seems to work (excluding the rotate which it doesn't have).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!