---
title: "How to recognize UITapGestureRecognizer to specific views in controller?"  
description: "How to recognize UITapGestureRecognizer to specific views in controller?"  
author: "Anonymous User"  
published: 2014-10-17  
updated: 2014-10-17  
canonical: https://www.mindstick.com/forum/2408/how-to-recognize-uitapgesturerecognizer-to-specific-views-in-controller  
category: "iphone"  
tags: ["iphone", "ios"]  
reading_time: 2 minutes  

---

# How to recognize UITapGestureRecognizer to specific views in controller?

I have a menu [controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc) that when it pops up has a [collection view](https://www.mindstick.com/forum/33803/how-to-set-collection-view-cell-size-in-ios). The way it works is that when the user taps outside the collection view it should make the menu dismiss. The menu dismisses when you [tap](https://answers.mindstick.com/qa/106164/tips-for-winning-in-mlb-tap-sports-baseball-2022) outside the collection view, but it also dismisses when you tap inside the collection view. I can't seem to get the [gesture](https://yourviews.mindstick.com/view/228/female-passenger-praised-uber-drivers-gesture) recognizer to only dismiss when it is not inside the collection view. I have looked around on here and [google](https://www.mindstick.com/articles/43833/google-lighthouse-and-how-is-it-changing-the-way-we-development-and-design-websites) and I haven't found any solution yet that works. Here is the [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) for the [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) that handles the tap:\

```
    @IBAction func handleTap(sender: MenuTapGestureRecognizer)    {        if (sender.state == .Ended && sender.view == menuCollectionView)        {            NSLog("menuCollectionView")        }        else if (sender.state == .Ended && sender.view == mainView)        {            self.dismissViewControllerAnimated(true, completion: nil)        }    }
```

## Replies

### Reply by Anonymous User

I suspect you have only attached the gesture recognizer to your mainView. This is fine, but you will want to use sender.locationInView(menuCollectionView) and check to see if the point is within the bounds of your [collection](https://www.mindstick.com/articles/1718/collections-in-java) [view](https://yourviews.mindstick.com/view/84701/layoffs-in-google-india-2023-view). This is done with the following:**\**

```
if (CGRectContainsPoint(menuCollectionView.bounds, sender.locationInView(menuCollectionView))) {  // do stuff.}
```


---

Original Source: https://www.mindstick.com/forum/2408/how-to-recognize-uitapgesturerecognizer-to-specific-views-in-controller

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
