6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UILongPressGestureRecognizerで2回同じセレクタが呼ばれる件

Posted at

開発初心者の自分のためのメモ。

//長押しの設定をする
-(void)viewDidLoad
{
   UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongPressGesture:)];
    longPressGestureRecognizer.delegate = self;
    [_AlbumCollection addGestureRecognizer:longPressGestureRecognizer];
}

ここで設定したメソッド、普通だと「長押し開始と認識されるタイミング」と「終了のタイミング」の2回呼ばれる。
なのでどちらかのタイミングに限定したいときは切り分けを行う。

-  (void)handleLongPressGesture:(UILongPressGestureRecognizer*)sender {
    if (sender.state == UIGestureRecognizerStateEnded) {
        NSLog(@"長押し終了のタイミング");
    }
    else if (sender.state == UIGestureRecognizerStateBegan){
        NSLog(@"長押し開始のタイミング");
   
    }
}
6
6
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?