ios - How can I use hitTest to get underlying views if they are in a table? -


this code me views beneath main view:

    override func touchesmoved(touches: set<uitouch>, withevent event: uievent?) {           let location = touches.first!.locationinview(self.view)           let view = self.view.hittest(location, withevent: event)           print("view: %@", nsstringfromclass((view?.classforcoder)!)) } 

is there way table? have table cells , want see cell user dragging over, or view within cell. goal use button disable scroll, able drag on table , print out cell or view within cell user drags on them.

you can query uitableview index-path based on cell subviews.

let point = cellsubview.convertpoint(cellsubview.bounds.origin, toview: tableview) let index = tableview.indexpathforrowatpoint(point) 

indexpathforrowatpoint() returns nil if point outside of row in table

edit: handle touches on tableview have set gesture recognizer on it.

let tapgesture = uitapgesturerecognizer(target: self, action: #selector(didtapontableview(_:))) tableview.addgesturerecognizer(tapgesture)  func didtapontableview(gesture: uitapgesturerecognizer){     let touchpoint = gesture.locationinview(tableview)     let index = tableview.indexpathforrowatpoint(touchpoint)      ... } 

Comments