1) Transfer the view of the object controller to the user cell
class ImageTableViewCell: UITableViewCell {
@IBOutlet weak var img: UIImageView!
var vc: UIViewController? = nil
var delegate: TouchLocation?
}
2) Override the user table view cell with the touchesBegan method and override the super touchesBegan method
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first
delegate?.touchLocation(location: (touch?.location(in: self.vc?.view))!)
if let aTouches = touches as? Set<UITouch>, let anEvent = event {
super.touchesBegan(aTouches, with: anEvent)
}
}
3) Get the location and go to viewing the controller using delegation
protocol TouchLocation {
func touchLocation(location: CGPoint)
}
extension ImageListViewController: TouchLocation{
func touchLocation(location: CGPoint) {
self.touchedPosition = location
}
}
source
share