How does one implement pinch gestures on the iPhone? I'm familiar with using touch events on the iPhone but I'm extremely lazy and don't want to re-invent the wheel for something as widespread as PINCH gestures...Source code or links thereto would be helpful.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- how do you prevent page scroll in textarea on mobi
- Custom UITableview cell accessibility not working
相关文章
- Could I create “Call” button in HTML 5 IPhone appl
- Unable to process app at this time due to a genera
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- Open iOS 11 Files app via URL Scheme or some other
- Can keyboard of type UIKeyboardTypeNamePhonePad be
- Can not export audiofiles via “open in:” from Voic
- XCode 4.5 giving me “SenTestingKit/SenTestKit.h” f
hmmm.....it seems that some people are extremely confused on how to use basic math. the dot product is totally irrelavent and just confuses the issues. dot prod between 2 vectors is used to calculate the angle between them.
You actually need to use pythagorus theorem. Dot is NOTHING to do with finding distance between points - only pythagorous!
Pretty sure the solutions presented here have been obsoleted, in favor of using the new UIPinchGestureRecognizer class in iOS 3.2 and later.
You need to implement it yourself using some basic math.
Those are the delegate methods that you need to implement in your application.
You need to get the distance between the two touches, then calculate the changes in distance in your own code.
The mathematical equation you use to get the distance is called the dot product
I just want to point out that the equation they use in the cited tutorial is incorrect. I have updated it to include the absolute value that is missed in the tutorial.
This is the dot product:
Edit: I made a mistake in my previous answer....it's been a while since I've done any of that kind of math.
If you don't square root the result, you won't get the true distance between the points. This is called calculating the magnitude between two vectors.
This is the proper way to do it. If you want to omit the sqrt, you will not have the exact distance between the two points.
If you don't square the answer, your code will work but it will be using measurements that are much larger than the actual values. So in the future if you need to get the distance between the two points, it will return something like 90000 instead of the actual pixel distance which would be 300px.
If you're looking for a simple code example of the pinch gesture, I use the method described by Brock in the example application I describe here (in the second-to-last and last versions of the application on that page). The pinch gestures are used to scale a couple of Core Animation layers in that example.
All he's describing as far as the distance calculation is simply the Pythagorean Theorem applied between two points (with the X and Y distances as the two faces of a right triangle).