swift - UITableView 点击手势行为

标签 swift uitableview uigesturerecognizer

当我点击表格 View 时,它将触发 touchesBegantouchesShouldBegin。不过,我的 View 单元格上还有一个 UIPanGestureRecognizer,并且在平移单元格时,点击其他单元格不会触发 touchesShouldBegin

我需要 touchesShouldBegin 的原因是我想在平移单元格时停止触摸。我可以使用其他方法来做到这一点吗?我尝试将 allowsMultipleSelection 设置为 falsetrue

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    print("This will always be printed")
}

override func touchesShouldBegin(_ touches: Set<UITouch>, with event: UIEvent?, in view: UIView) -> Bool {
    print("This will only be printed when no cells are being panned")

    return true
}

最佳答案

尝试将 UITableViewdelaysContentTouches 属性设置为 true

您还可以尝试将 UIGestureRecognizerDelegate 添加到 UIPanGestureRecognizer 并具有:

extension MyViewController: UIGestureRecognizerDelegate {
  func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
    return true
  }
}

关于swift - UITableView 点击手势行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41116649/

相关文章:

ios - ipad air 2 多任务处理取代了详细信息 View 上的主视图

swift - 如何自定义 PDFView 的上下文菜单?

ios - KeyboardWillHide 在 KeyboardWillShow 仍在动画时被调用

ios - 简单地继承 UITouchGestureRecognizer,设置 minimumPressDuration

ios - 拖动 UIView 结束时会丢失手势

swift - UIBezierPath 在右上角和右下角不起作用

ios - 单个 UIViewcontroller 中的两个 UITableView 无法正常工作

iphone - 想要在 UITableView 中从右向左滑动时显示删除按钮

ios - 如何让 UITableView 标题 View 出现在响应链中的表格单元格之前?

ios - 单击 UITableView 中的标签时,tableview 单元格中的 IndexPath 返回错误