カスタム UIGestureRecognizer を実装しています。簡単にするために、1 回以上のタッチで構成されるジェスチャを認識すると仮定します。
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
ここにセレクタがあります:
- (IBAction)handleGesture:(Gesture *)recognizer {
printf("%s %d\n", __FUNCTION__, recognizer.state);
}
そして、ここに出力があります:
-[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.
セレクターが UIGestureRecognizerStateBegan を受信しないのはなぜですか?