[英]UIPanGestureRecognizer gets called twice on cell
我正在创建一个UITableView
,您可以从中拖动到另一个UIView
并将该单元格转换为自定义UIView
。 我通过向每个单元格添加一个UIPanGestureRecognizer
来做到这一点,如果向左滑动,我会创建自定义UIView并为其提供recognizer
。 所有这些工作都很好,只是有时会调用多个识别器。 最终将其拖动到自定义视图及其下的单元格。 我不知道两个视图如何同时识别出锅。 我不能让方法shouldRecognizeSimultaneouslyWithGestureRecognizer
返回NO
,因为我必须支持表的scrollView。
这是拖动的代码:
-(void)dragCell:(UIPanGestureRecognizer *)recognizer
{
CGPoint touchLocation = [recognizer locationInView:self.view];
if (recognizer.state == UIGestureRecognizerStateBegan)
{
gestureWasHandled = NO;
startPoint = touchLocation;
}
if (recognizer.state == UIGestureRecognizerStateChanged)
{
float dx = startPoint.x - touchLocation.x;
float dy = startPoint.y - touchLocation.y;
BOOL finished = YES;
BOOL swipeLeft = NO;
if ((dx > SWIPE_DRAG_MIN) && (ABS(dy) < DRAGLIMIT_MAX))
swipeLeft = YES;
else
finished = NO;
if (!gestureWasHandled && finished && swipeLeft)
{
[symptomsTableView setScrollEnabled:NO];
UITableViewCell *cell = (UITableViewCell *) recognizer.view;
NSIndexPath *index = [symptomsTableView indexPathForCell:cell];
SymptomView *view = [self createSymptomViewAtLocation:touchLocation withSymptom:symptomsInTableView[index.row]];
[symptomsInTableView removeObjectAtIndex:index.row];
[cell removeGestureRecognizer:recognizer];
[view addGestureRecognizer:recognizer];
gestureWasHandled = YES;
[symptomsTableView reloadData];
}
else if (gestureWasHandled)
{
SymptomView *view = (SymptomView *) recognizer.view;
view.center = touchLocation;
}
}
if (recognizer.state == UIGestureRecognizerStateEnded)
{
gestureWasHandled = NO;
[symptomsTableView setScrollEnabled:YES];
SymptomView *view = (SymptomView *) recognizer.view;
[view removeGestureRecognizer:recognizer];
[symptomsTableView reloadData];
}
}
在viewDidLoad方法中添加self.tableview.canCancelContentTouches = YES
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.