gpt4 book ai didi

ios - View 上的 UISwipeGestureRecognizer - 如果触摸位于 UITableViewCell 内部,如何将其传递到单元格?

转载 作者:行者123 更新时间:2023-11-29 03:55:46 25 4
gpt4 key购买 nike

我在 View 中添加了一个 UISwipeGestureRecognizer,它根据用户滑动的方向(向左或向右)更改 View 的内容。但是,如果用户在 UITableViewCell 中滑动,则触摸会被忽略,并且滑动删除功能永远不会显示。如何将此触摸传递给 UITableViewCell?

我做了什么:

    [swipeLeft setCancelsTouchesInView:NO];
[swipeRight setCancelsTouchesInView:NO];


-(void)swipeLeft:(UISwipeGestureRecognizer *)gesture {
BOOL touchedInsideCell = NO;
CGPoint touchedPoint = [gesture locationInView:gesture.view];
for (PCFCustomScheduleCell *cell in self.tableView.visibleCells) {
CGRect cellFrame = cell.frame;
if (CGRectContainsPoint(cellFrame, touchedPoint)) {
touchedInsideCell = YES;
break;
}
}
if (touchedInsideCell == NO) {
if (recordOfDay < 5) {
recordOfDay++;
[self.tableView reloadData];
}

}else {
//I need to pass the touch to the UITableViewCell, as the swipe to delete feature is not working
}
}

我已经在 canEditRowAtIndexPath 方法中返回了 YES,如果我不添加这些手势识别器,它就会起作用。我错过了什么?

谢谢!

最佳答案

让您的类成为手势识别器的委托(delegate),然后您可以决定手势是否应处理任何传入的触摸。

关于ios - View 上的 UISwipeGestureRecognizer - 如果触摸位于 UITableViewCell 内部,如何将其传递到单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16531243/

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