My first answer, even with the sketch, was dirty. I deleted it.
So, here are some ways to achieve what you are looking for. We will assume that your region is a UIView.
Solution 1
You are extracting a point from the main view. , so you need to check if the frame of your regionView supports your point.
import UIKit class ViewController: UIViewController { @IBOutlet var regionView: UIView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let tap = UITapGestureRecognizer() tap.addTarget(self, action: "handleTap:") self.view.addGestureRecognizer(tap) } func handleTap(tap: UITapGestureRecognizer) { if (tap.state == UIGestureRecognizerState.Ended) { println("[handleTap] Tap ended") var point = tap.locationInView(self.view) println("[handleTap] Tap point : x\(point.x) ; y\(point.y) (in self.view)") if (CGRectContainsPoint(self.regionView.frame, point)) { println("[handleTap] Tap is inside regionView") } println() } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
Decision 2
You extract the point and convert it to the regionView internal coordinate system . Therefore, you need to check if the point is within the borders of your region.
import UIKit class ViewController: UIViewController { @IBOutlet var regionView: UIView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let tap = UITapGestureRecognizer() tap.addTarget(self, action: "handleTap:") self.view.addGestureRecognizer(tap) } func handleTap(tap: UITapGestureRecognizer) { if (tap.state == UIGestureRecognizerState.Ended) { println("[handleTap] Tap ended") var point = tap.locationInView(self.view) println("[handleTap] Tap point : x\(point.x) ; y\(point.y) (in self.view)") point = self.regionView.convertPoint(point, fromView: self.view) println("[handleTap] Tap point converted : x\(point.x) ; y\(point.y) (in self.regionView)") if (CGRectContainsPoint(self.regionView.bounds, point)) { println("[handleTap] Tap is inside regionView") } println() } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
Decision 3
You get a point from your regionView directly. This way you do not need to convert , but you still need to check if it is within the limits like solution 2.
import UIKit class ViewController: UIViewController { @IBOutlet var regionView: UIView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let tap = UITapGestureRecognizer() tap.addTarget(self, action: "handleTap:") self.view.addGestureRecognizer(tap) } func handleTap(tap: UITapGestureRecognizer) { if (tap.state == UIGestureRecognizerState.Ended) { println("[handleTap] Tap ended") var point = tap.locationInView(self.regionView) println("[handleTap] Tap point : x\(point.x) ; y\(point.y) (in self.view)") if (CGRectContainsPoint(self.regionView.bounds, point)) { println("[handleTap] Tap is inside regionView") } println() } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
Alternatively, you can set your gesture recognizer in regionView: self.regionView.addGestureRecognizer(tap) .
Let me know if this helped!