2

在我的长按手势中,我遇到了一个问题,例如,

*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 的值正在打印TWICE。为什么会发生?

4

1 回答 1

4

To check the state of the UILongPressGestureRecognizer just add an if statement on the selector method:

- (void)pressdetected:(UILongPressGestureRecognizer*)sender { 
if (sender.state == UIGestureRecognizerStateEnded) {
    NSLog(@"Long press Ended");
}
else {
    NSLog(@"Long press detected.");
}
}  
于 2012-11-02T09:37:56.590 回答