在我的长按手势中,我遇到了这样的问题,
*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 的值将打印两次。为什么会发生这种情况?
最佳答案
要检查 UILongPressGestureRecognizer 的状态,只需在选择器方法上添加 if 语句:
- (void)pressdetected:(UILongPressGestureRecognizer*)sender {
if (sender.state == UIGestureRecognizerStateEnded) {
NSLog(@"Long press Ended");
}
else {
NSLog(@"Long press detected.");
}
}
关于objective-c - ONLongPress手势检测两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13192614/