【问题标题】:Table View selection and pan gesture表格视图选择和平移手势
【发布时间】:2015-07-15 05:38:33
【问题描述】:

我有一个带有平移手势的表格视图。当我开始上下平移 tableview 时,tableview 选择被禁用,我无法选择 tableview 单元格。

UIPanGesture* tablePanGesture =[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(gestureHandler:)];
tablePanGesture.delegate = self;
[tableView addGestureRecognizer:tablePanGesture];
[tablePanGesture setCancelsTouchesInView:NO];

我使用以下委托让我的手势和 tableview 手势一起工作:

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{

    return YES;
}

我已经实现了表格视图 didSelectRowAtIndexPath 的方法,但是当我使用平移时,它没有被调用。 pan手势和tableview Delegate有冲突吗?

【问题讨论】:

  • 你为什么使用平移手势
  • @LalitKumar 我想向上平移表格,然后启用滚动,如果内容偏移量为零并且表格正在拖动,则将其向下平移。
  • 这样做的目的是什么??
  • @NJGadhiya 我有一个向用户显示列表的表格视图,我希望用户能够缩小表格视图然后滚动它
  • 您可以使用UIScrollViewDelegate方法检测UITableView的上/下滚动。因此,如果滚动代理达到目的,您可以删除平移手势。

标签: ios objective-c iphone uitableview uigesturerecognizer


【解决方案1】:

您缺少这一行:-

[tablePanGesture setCancelsTouchesInView:NO];

这将使 UIPanGesture 识别平移手势并将触摸传递给下一个响应者,这意味着您的表格视图选择或点击。

【讨论】:

  • 感谢您的回复,我尝试添加它但它不起作用,请您详细说明我需要在哪里添加它?
  • 你能更新代码吗.. 你在哪里添加了这个tablePanGesture setCancelsTouchesInView:NO]; 行。
  • 已更新,我尝试将它添加到不同的地方但它不起作用。
  • 这适用于我在 Swift 4.2 上。该方案不适用于 OP 的原因是手势直接添加到 tableview 上。您可以在他的第一个格式化代码块的第 3 行中看到这一点。我尝试了两种方法 - 在 tableview 和 ViewController 视图上,添加到 ViewController 视图允许 PanGesture 与 tableview 触摸一起工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-12
相关资源
最近更新 更多