UILongPressGestureRecognizer issue

2020-04-20 12:10发布

i have one issue regarding UILongPressGestureRecognizer, i have add gesture like below of the code

**ViewDidLoad**
UILongPressGestureRecognizer *_longRecognizer = [[UILongPressGestureRecognizer alloc]      initWithTarget:self action:@selector(ICN_TRASH_Click:)]; 
NSArray *recognizerArray = [[NSArray alloc] initWithObjects:_longRecognizer, nil];

[[self.view viewWithTag:2001] setGestureRecognizers:recognizerArray];

 OnClick
 if ([sender isKindOfClass:[UILongPressGestureRecognizer class]])  
{

  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Are you sure delete all message ?" delegate:self cancelButtonTitle:@"Yes" otherButtonTitles:@"No",nil];
  [alert show];
  [alert release];

}

So we Long press on button two times call alertview, does anyone have a idea, why facing this issue.

1条回答
爷、活的狠高调
2楼-- · 2020-04-20 12:41

So you press the button (then release it I guess) and you are getting the message two times?

Perhaps you should check the state of the GestureRecognizer (like if it's the begin phase or end phase) GestureRecognizer state.

查看更多
登录 后发表回答