I have a 2d map that the user can zoom and pan using the gesture recognizers. While it works, i want the user to start panning immediately after a zoom once they have 1 finger lifted. Unfortunately, in the docs it says:
The gesture ends (UIGestureRecognizerStateEnded) when both fingers
lift from the view.
which is pretending me from going from a pinch zoom to a pan right away. What could i do to fix this?
This is possible, and easy! It involves being your gesture recognizer’s delegate. Something no-one seems to know exists. In my view controller subclass I have declared both conforming to the protocol
<UIGestureRecognizerDelegate>and two ivars:These ivars are instantiated in view did load. Notice setting self as the delegate.
One of the delegate calls made by a
UIGestureRecognizerisshouldRecognizeSimultaneouslyWithGestureRecognizer:if I had more than two gesture recognizers then this function would have to contain some logic. But since there are only two I can just returnYES.Now you do have to include a little (very little) extra logic in your action methods to screen for the appropriate conditions.
Run this code an look at the logs. you will see when you move one finger you will see “panny” when you place a second finger down you will see “pinchy”, and back and forth.