Touch event handled by multiple views

后端 未结 3 1269
挽巷
挽巷 2021-02-06 03:39

I have a subclass of UIView on top of a UITableView. I am using the UITableView to display some data and, at the same time, I would like t

3条回答
  •  旧巷少年郎
    2021-02-06 04:23

    No, you cann't do it implicity. Event Delivery chapter says

    The window object uses hit-testing and the responder chain to find the view to receive the touch event. In hit-testing, a window calls hitTest:withEvent: on the top-most view of the view hierarchy; this method proceeds by recursively calling pointInside:withEvent: on each view in the view hierarchy that returns YES, proceeding down the hierarchy until it finds the subview within whose bounds the touch took place. That view becomes the hit-test view.

    So, when window finds touched view it returns YES. Only one view can handle touches at the current moment.

    But if you need to handle event for UITableView then handle it for UIView! You can convert touched point to required coordinates with – convertPoint, – convertRect functions, add subview to UITableView and move it depends on coordinate, and a lot of another things.

提交回复
热议问题