UILongPressGestureRecognizer 缺少 UIGestureRecognizerStateBegan 状态!
所以我实现了一个1指长按手势识别器,但识别器似乎总是缺少 UIGestureRecognizerStateBegan 状态... 如果我长按而不移动手指并抬起,我会收到 StateEnded 调试消息。 如果我长按并稍微移动手指然后抬起,我会收到 StateChanged 和 StateEnded 调试消息。 但我从未见过 StateBegan。
UIPanGestureRecognizer 不存在此问题 - Pan 从开始 -> 更改 -> 结束中获取所有正确的手势状态。
- (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer {
CGPoint location = [recognizer locationInView:self];
switch (recognizer.state) {
case UIGestureRecognizerStateBegan:
NSLog(@"!!!!handleLongPress: StateBegan !!!!!");
break;
case UIGestureRecognizerStateChanged:
NSLog(@"!!!!handleLongPress: StateChanged !!!!!");
break;
case UIGestureRecognizerStateEnded:
NSLog(@"!!!!handleLongPress: StateEnded !!!!!");
break;
default:
break;
}
}
so I have implemented a 1-finger long-press gesture recognizer, but the recognizer always seems to be missing the UIGestureRecognizerStateBegan state...
If I long press w/o moving finger and lift, I get the StateEnded debug message.
If I long press and move finger a bit then lift, I get the StateChanged and StateEnded debug messages.
But I never see StateBegan.
Don't have this issue with UIPanGestureRecognizer - Pan gets all the correct gesture states from Began->Changed->Ended.
- (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer {
CGPoint location = [recognizer locationInView:self];
switch (recognizer.state) {
case UIGestureRecognizerStateBegan:
NSLog(@"!!!!handleLongPress: StateBegan !!!!!");
break;
case UIGestureRecognizerStateChanged:
NSLog(@"!!!!handleLongPress: StateChanged !!!!!");
break;
case UIGestureRecognizerStateEnded:
NSLog(@"!!!!handleLongPress: StateEnded !!!!!");
break;
default:
break;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了类似的问题,这是由 UILongPressGestureRecognizer 设置引起的:我使用的原始示例代码指定了 numberOfTapsRequired = 1,我必须快速点击并释放,然后长按才能使其工作,而不是只需点击并按住几秒钟即可。当我删除 numberOfTapsRequired 时,代码现在的行为符合我的预期。希望这有帮助 =)
I was having a similar problem and it was caused by the UILongPressGestureRecognizer setup: the original sample code I was using specified the numberOfTapsRequired = 1, and I had to quick-tap and release, and THEN long-tap to make it work, instead of just tapping and holding for a couple of seconds. When I removed the numberOfTapsRequired the code now behaved as I expected. Hope this helps =)