4

I'm trying to implement a tap gesture recognizer into my app. Ideally I need for the tap gesture to return the x and y coordinates, so I can then create a variable to apply to a core image filter using a parameter which requires the x and y values. e.g, the user taps their nose, the gesture recognizer passes the coordinates(a variable, say, nosePosition.x and nosePosition.y) into a filter such as CIBumpDistorion, which need the x and y values for its kCIInputCenterKey.

I have tried using quite a few methods and moving/deleting code all to no avail. So if anyone has some advice I would be very grateful!

jrbedard
  • 3,662
  • 5
  • 30
  • 34
Henry
  • 41
  • 1
  • 2

1 Answers1

10

Would that work ?

func touch(sender: UITapGestureRecognizer) {
    let point = sender.locationInView(self.view)
    let x = point.x
    let y = point.y
}
La masse
  • 1,190
  • 1
  • 10
  • 24
  • Hi La masse, Thanks for your reply. I'll give it a try later, hopefully it'll work! – Henry Nov 22 '16 at 16:43
  • Perfect, thank you. One change is that sender.locationInView(self.view) has changed to sender.location(in: self.view) – Dominick Dec 03 '19 at 18:53