gpt4 book ai didi

iphone - 点击手势 + 长按手势都不能一起工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:08:12 24 4
gpt4 key购买 nike

我想在 View 中同时使用点击手势和长按手势。但我的问题是我无法在点击时运行点击手势操作。但长按手势工作正常。

这是代码片段。

            UILongPressGestureRecognizer *longPressGesture=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(ontappLongPressGesture:)];
longPressGesture.minimumPressDuration=0.6;

longPressGesture.delegate=self;
[cell.view addGestureRecognizer:longPressGesture];

UITapGestureRecognizer *gesture=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cellSelected:)];
//[gesture requireGestureRecognizerToFail:longPressGesture]; //I have tried with this line also but not working
gesture.delegate=self;
[cell.view addGestureRecognizer:gesture];

我也设置了委托(delegate)方法

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

这个方法在长按时被调用

- (void)ontappLongPressGesture:(id)sender{

//Long press code here

}

但是这个方法不会在点击时被调用

-(void)cellSelected:(id)sender {

//Single tap code here

}

最佳答案

您没有指定将这些 gestureRecognizer 放在什么类型的 View 上,但是由于您称它为“单元格”,我假设它在 UITableView 上?

如果是这样,您需要确保设置了 cancelsTouchesInView 标志:

gesture.cancelsTouchesInView=NO;

关于iphone - 点击手势 + 长按手势都不能一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17912169/

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