I have a problem with my current code, it works to detect the zoom, and i think my code detects the difference between rotation and pinch, but if i put two fingers down and swipe it still zooms. How do i detect this and stop it? I also have to accomodate for users being sloppy when pinching and zoom and move fingers sideways a little bit (probably defining a variable that can be changed)
Here is my current code:
How do i edit this to detect if a user swipe with two fingers and pinches to zoom? (i also have to take into account a user can have the pinch horizontal, vertical, or a combo of the two diagonally which i tried doing with the midpoint code.
asked Nov 05 '11 at 09:11 PM
first, whining never helps, it won't get you pity or sympathy. You're asking for help from people who have no reason to help you and do not stand to benefit in any way from doing so; you're entitled to nothing. Remember that.
That said, I'll attempt to help anyway this time, despite your attitude, because I do understand your frustration.
This is basically a variation of the standard mouse dragging vs clicking problem, and the same solution ought to work. What you need is some state information.
in Idle state:
check for a two-finger touch. If you get one, remember the finger positions and calculate and store the distance between them, and change state to TwoFingerTouch.
in TwoFingerTouch state:
If one or both touches have ended: compare their final positions to their originals. If they've both moved in the same general direction, and moved far enough to qualify as a swipe, ... do a swipe, and go back to the Idle state. If they moved different directions, or not far enough, go back to Idle state.
If both touches are still there, calc the current distance between them. If it's reduced enough, transition to PinchZoom state.
in PinchZoom state:
Calculate the new distance between the fingers, and apply zoom level based on this relative to original distance between them.
If one or both fingers released, return to Idle state.
As for how to implement this simple state machine, there are many ways, a search for State Machines will probably find you many examples. Here's one very simple way it could be done:
answered Nov 20 '11 at 02:22 AM
Since I'm not sure what your question is, I'll go with the title and give you my C# script that will detect pinch. This is extracted from a 342 lines of code bloated script, so I'm sorry if I'm missing something. Just let me know and I'll dig deeper to fix it:
Hope this is enough to help you!
answered Nov 21 '11 at 07:49 PM