gpt4 book ai didi

ios - Swipe Gesture 多次调用该方法

转载 作者:行者123 更新时间:2023-11-29 10:43:57 30 4
gpt4 key购买 nike

我有一个小问题 em 卡住了..我有一个自定义 UITableViewCell,在它的 textView 上我添加了 2 个手势UITapGestureUISwipeGesture..点击手势 工作正常,但滑动手势 调用方法多次.. 有时调用它两次,有时甚至更多......这是我将它们添加到单元格的方式

//added in cellForRowAtIndexPath Method
UITapGestureRecognizer *tapToTranslate = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapToTranslate:)];
[tapToTranslate setNumberOfTapsRequired:1];
[tapToTranslate setNumberOfTouchesRequired:1];
tapToTranslate.delegate = self;
[cell.messageContentView addGestureRecognizer:tapToTranslate];


UISwipeGestureRecognizer *swipeToTranslate = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(translateTo:)];
swipeToTranslate.numberOfTouchesRequired = 1;
swipeToTranslate.direction = UISwipeGestureRecognizerDirectionLeft;
swipeToTranslate.delegate = self;
[cell.messageContentView addGestureRecognizer: swipeToTranslate];

有这些方法……

-(void)tapToTranslate:(UITapGestureRecognizer *)aGesture {}

-(void)translateTo:(UISwipeGestureRecognizer *)aGesture
{
aGesture.enabled = false;
}

我尝试在调用后在其方法中禁用 Swipe Gesture,但这没有帮助..

我还有 uigesturerecognizer 委托(delegate)方法

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}

所以任何帮助都会很棒......提前致谢……

编辑 1

<UITextView: 0x11322f700; frame = (18 10; 160.865 69.2656); text = '你怎么样?    How are you doing?'; clipsToBounds = YES; gestureRecognizers = <NSArray: 0x11322fbd0>; layer = <CALayer: 0x11322fac0>; contentOffset: {0, 0}>

最佳答案

UISwipeGestureRecognizer 会针对不同的状态多次调用该函数,例如 UIGestureRecognizerStateBeganUIGestureRecognizerStateEnded 和其他几种状态。它还会在滑动时不断调用该函数,这可以在下面的最后一个 else 语句中处理。在滑动手势功能中,执行以下操作:

-(void)translateTo:(UISwipeGestureRecognizer *)aGesture
{
if (recognizer.state == UIGestureRecognizerStateBegan)
{
//do something
}
else if(recognizer.state==UIGestureRecognizerStateEnded)
{
}
else
{
//do something while it is swiping
}
}

以下答案可能与您打算做的不一致,但仍可能对您有所帮助:UISwipeGestureRecognizer called twice

关于ios - Swipe Gesture 多次调用该方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23126573/

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