UILongPressGestureRecognizerは、長押し開始時と、長押し終了時の2回、イベントを送信する。長押し判定の秒数を1秒に指定して、3秒間の長押しをした場合、押し始めて1秒で長押し開始、離した瞬間(3秒の時点)に長押し終了イベントを発生させる。どちらか片方でしかイベントを実行したくない場合は以下のようにする。
- (void)handleLongPress:(UILongPressGestureRecognizer*)sender {
if (sender.state == UIGestureRecognizerStateEnded) {
NSLog(@"UIGestureRecognizerStateEnded");
//Do Whatever You want on End of Gesture
}
else if (sender.state == UIGestureRecognizerStateBegan){
NSLog(@"UIGestureRecognizerStateBegan.");
//Do Whatever You want on Began of Gesture
}
}
if (sender.state == UIGestureRecognizerStateEnded) {
NSLog(@"UIGestureRecognizerStateEnded");
//Do Whatever You want on End of Gesture
}
else if (sender.state == UIGestureRecognizerStateBegan){
NSLog(@"UIGestureRecognizerStateBegan.");
//Do Whatever You want on Began of Gesture
}
}
StackOverFlow:UILongPressGestureRecognizer gets called twice when pressing down