gpt4 book ai didi

ios - uilongpressgesturerecognizer 只触发一次

转载 作者:可可西里 更新时间:2023-11-01 04:17:07 25 4
gpt4 key购买 nike

我想添加一个手势,只有当一个人按下一秒钟左右时才会触发。不是轻按,而是长按。如果我使用 uilongpressgesturerecognizer,它会一直发射,直到我松开手指。我该如何解决这个问题。

最佳答案

在创建和添加手势时设置minimumPressDuration,如下所示:

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 1.0;

UIGestureRecognizerStateEnded 状态下编写代码,如下所示:

-(void)handleLongPress:(UILongPressGestureRecognizer *)Gesture{

if (Gesture.state == UIGestureRecognizerStateEnded) {


//Do any thing after long press ended,which will be 1.0 second as set above


}
else if (Gesture.state == UIGestureRecognizerStateBegan){



}
}

关于ios - uilongpressgesturerecognizer 只触发一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37812836/

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