gpt4 book ai didi

iphone - UILongPressGestureRecognizer 仅在移动手指时识别

转载 作者:行者123 更新时间:2023-12-03 20:32:36 28 4
gpt4 key购买 nike

我尝试在我的应用程序中使用 UILongPressGestureRecognizer,问题是该函数仅在我稍微移动手指时调用。

这是我正在使用的代码:

    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(doRewind)];
[uiNextButton addGestureRecognizer:longPress];

最佳答案

我知道我迟到了回答这个问题,但我认为这可能会对某人有所帮助。我也遇到了同样的问题。我需要触发事件并移动到下一个屏幕,而无需移动或触摸屏幕。由于手势识别器有不同的状态:

UIGestureRecognizerStateBeganUIGestureRecognizerStateEnded

我正在使用 UIGestureRecognizerStateEnded ,这造成了问题,因为它首先检查状态是否已经开始,并且在不移动手指的情况下事件没有触发。因此,我将 UIGestureRecognizerStateEnded 状态替换为UIGestureRecognizerStateBegan 一切正常。现在您无需将手指移开。只需按住,一切正常。

if (gesture.state == UIGestureRecognizerStateBegan) {
// Do your stuff
}

这是正确的方法,其他方法如 numberOfTapsRequiredallowableMovement 都有不同的用途。

关于iphone - UILongPressGestureRecognizer 仅在移动手指时识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6895291/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com