1. ヘッダファイルに、UIGestureRecognizerDelegate を定義していること。
@interface ViewController : UIViewController< UIGestureRecognizerDelegate >
2. delegate に selfを設定していること。
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)];
longPressGesture.allowableMovement = 5.0; // 指のズレを許容する範囲 5px
longPressGesture.minimumPressDuration = 2.0; // イベントが発生するまでタップする時間(秒)
longPressGesture.numberOfTapsRequired = 0; // タップする回数 1回の場合は[0] 2回の場合は[1]を指定
longPressGesture.numberOfTouchesRequired = 1; // タップする指の数
longPressGesture.delegate = self;
[self.view addGestureRecognizer:longPressGesture];
3. shouldRecognizeSimultaneouslyWithGestureRecognizer メソッドの戻り値に、YESを設定していること。
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES;
}
参考記事:
http://stackoverflow.com/questions/14686406/uilongpressgesturerecognizer-not-working