I am using a custom UIGestureRecognizer. For simplicity, suppose that it recognizes a gesture consisting of> 1 touches.
Here is Gesture.m:
#import "Gesture.h" #import <UIKit/UIGestureRecognizerSubclass.h> #define SHOW printf("%s %d %d %d\n", __FUNCTION__, self.state, touches.count, self.numberOfTouches) @implementation Gesture - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { SHOW; if (self.numberOfTouches==1) return; self.state = UIGestureRecognizerStateBegan; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { SHOW; if (self.numberOfTouches==1) return; self.state = UIGestureRecognizerStateChanged; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { SHOW; if (self.numberOfTouches==1) return; self.state = UIGestureRecognizerStateEnded; } @end
Here is the selector:
- (IBAction)handleGesture:(Gesture *)recognizer { printf("%s %d\n", __FUNCTION__, recognizer.state); }
And here is the conclusion:
-[Gesture touchesBegan:withEvent:] 0 1 1 // 1st touch began -[Gesture touchesMoved:withEvent:] 0 1 1 -[Gesture touchesMoved:withEvent:] 0 1 1 -[Gesture touchesMoved:withEvent:] 0 1 1 -[Gesture touchesBegan:withEvent:] 0 1 2 // 2nd touch began -[Gesture touchesMoved:withEvent:] 1 1 2 // Gesture.state==UIGestureRecognizerStateBegan but selector was not called -[ViewController handleGesture:] 2 // UIGestureRecognizerStateChanged received. -[Gesture touchesMoved:withEvent:] 2 2 2 -[ViewController handleGesture:] 2 -[Gesture touchesMoved:withEvent:] 2 2 2 -[ViewController handleGesture:] 2 -[Gesture touchesMoved:withEvent:] 2 2 2 -[ViewController handleGesture:] 3 // UIGestureRecognizerStateEnded received.
Why doesn't the selector get a UIGestureRecognizerStateBegan?
Alexp source share