The message sent to the touch gestures is basically similar to the location of the tapping element found in the view.
Suppose we have added a touch gesture in the self.view controller view.
override func viewDidLoad() { super.viewDidLoad() let tapGesture = UITapGestureRecognizer(target: self, action:
We can implement the printGesPosition method as
func printGesPostion(ges:UITapGestureRecognizer) { print(ges.locationInView(self.view)) let subView = self.view.hitTest(ges.locationInView(self.view), withEvent: nil) if subView?.isKindOfClass(UILabel) == true { print( (subView as! UILabel).text! ) } }
In this case, the method detects the position of the tap gestures; if it occurs on a UILabel , it will print label.text
Remember to set label.userInteraction = true , either in ViewDidLoad or just in the storyboard.
source share