将UITableView的默认Pan手势传递给另一个UIView。

huangapple go评论48阅读模式
英文:

Pass UITableView default PanGesture to another UIView

问题

我有一个UITableView,垂直覆盖在一个UIView上,而该视图具有UIPangestureRecognizer。现在,如果用户尝试滚动tableView,并且手指指向没有单元格的位置,我希望第二个视图的panGesture响应。

英文:

I have an UITableView, vertically covered over a UIView and that View have UIPangestureRecognizer. Now if user try to scroll tableView and if finger point have no cell I want second views panGesture response.

答案1

得分: 0

子类化UITableView并覆盖hitTest方法。

-> 如果手指所在位置有单元格,则返回self

-> 否则返回nil或任何其他应该响应的视图。

代码:

class MyTableView: UITableView {
    override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
        if indexPath(at: point) != nil {
            return self
        } else {
            return nil
        }
    }
}
英文:

Subclass UITableView and override hitTest method.

-> if finger point have cell return self

-> else return nil or any other view that should response

Code:

class MyTableView: UITableView {
    override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
        if indexPath(at: point) != nil {
            retrn self
        } else {
            return nil
        }
    }
}

huangapple
  • 本文由 发表于 2023年2月7日 01:26:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75364611.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定