当你使用longPress gesture recognizer 时,你可能会发现调用了多次。

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];

longPress.delegate = self;

[self.view addGestureRecognizer:longPress];

其实时因为响应不同的状态。所以,要在你的方法里加上状态的判断。可以看到,开始响应,结束响应,如果你不判断的话,都会调用你的方法。

- (void)longPress:(UILongPressGestureRecognizer *)sender {

    if (sender.state == UIGestureRecognizerStateBegan) {
    
         [self yourMethod];

    }

}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-08
  • 2021-10-26
  • 2022-12-23
  • 2022-01-20
猜你喜欢
  • 2021-09-26
  • 2022-12-23
  • 2021-06-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案