Is it possible to fire a UIPinchGestureRecognizer action just once?
I want to enable my users to pinch (actually spread) to fire of an action but the method gets called constantly which I understand is the functionality of a UIPinchGestureRecognizer.
UPDATED CODE USING ANSWER BELOW (just detects zoom):
-(void) handlePinchGesture: (UIPinchGestureRecognizer *) sender {
if (sender.state == UIGestureRecognizerStateBegan) {
self.startingScale = sender.scale;
}
if (sender.state == UIGestureRecognizerStateEnded) {
if (sender.scale > self.startingScale) {
[self zoomIn];
}
}
}
Gesture recognizers are state machines, and if you don’t specify which state you want to listen to simply calling a selector from a gesture will fire for any/every state across the board.
To limit detection to when the gesture starts you can use:
Other recognition states include: