Harish
Harish

Reputation: 2512

UILongPressGesture detecting twice

In my longpress gesture i have an problem like,

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

my function:

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

here when i press for more than 3 seconds, the value of my A is printing TWICE. why it happens?

Upvotes: 2

Views: 561

Answers (1)

user1534324
user1534324

Reputation:

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.");
}
}  

Upvotes: 4

Related Questions