Objective c UILongPress手势检测两次

Objective c UILongPress手势检测两次,objective-c,uigesturerecognizer,Objective C,Uigesturerecognizer,在我的长按手势中,我有一个问题,比如 *mypressrec = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(pressdetected:)]; mypressrec.minimumPressDuration = 3;

在我的长按手势中,我有一个问题,比如

*mypressrec = [[UILongPressGestureRecognizer alloc]
                                         initWithTarget:self 
                                         action:@selector(pressdetected:)];
    mypressrec.minimumPressDuration = 3;
    [self addGestureRecognizer:mypressrec];
    [mypressrec release];
我的职能:

    -(void)pressdetected:(UILongPressGestureRecognizer*)recognizer{
     //My code goes here
  a=90;
   NSLog(@"value of my A",a);
}

在这里,当我按下超过3秒时,我的A值会打印两次。为什么会发生这种情况?

要检查UILongPressGestureRecognitor的状态,只需在选择器方法上添加一条if语句:

- (void)pressdetected:(UILongPressGestureRecognizer*)sender { 
if (sender.state == UIGestureRecognizerStateEnded) {
    NSLog(@"Long press Ended");
}
else {
    NSLog(@"Long press detected.");
}
}  

要检查UILongPressGestureRecognitor的状态,只需在选择器方法上添加一条if语句:

- (void)pressdetected:(UILongPressGestureRecognizer*)sender { 
if (sender.state == UIGestureRecognizerStateEnded) {
    NSLog(@"Long press Ended");
}
else {
    NSLog(@"Long press detected.");
}
}