UILongPressGestureRecognizer 缺少 UIGestureRecognizerStateBegan 状态!

发布于 2024-09-11 04:18:52 字数 869 浏览 1 评论 0原文

所以我实现了一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痕至 2024-09-18 04:18:52

我遇到了类似的问题,这是由 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 =)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文