Reputation: 2512
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
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