Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8515461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:09:10+00:00 2026-06-11T05:09:10+00:00

I have a view with some tables and buttons on it, and then I

  • 0

I have a view with some tables and buttons on it, and then I want to add a tap gesture to the entire view, but I only want that gesture recognizer to recognize taps.

Ideally, I want to do something when the added gesture recognizer is tapped, then remove that gesture recognizer after so the other buttons and tables can be accessed. Basically a tap to dismiss functionality that replicates something like the facebook notifications window, tap outside to dismiss, but not interfere with the buttons outside of the notifications view.

Can anybody help?

My current code is:

    NotificationsWindow *customView = [[[NSBundle mainBundle]loadNibNamed:@"NotificationsWindow" owner:self options:nil]objectAtIndex:0];
    customView.frame= CGRectMake(12, 12, customView.frame.size.width, customView.frame.size.height);

    UITapGestureRecognizer *recognizerForSubView = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapBehindAgain:)];
    [recognizerForSubView setNumberOfTapsRequired:1];
    recognizerForSubView.cancelsTouchesInView = NO; //So the user can still interact with controls in the modal view
    [customView addGestureRecognizer:recognizerForSubView];


    [self.view addSubview:customView];

    [self catchTapForView:customView.superview];

(void)handleTapBehind:(UITapGestureRecognizer *)sender
{
    NSLog(@"tapped");

    [[self.view.subviews lastObject] removeFromSuperview];
    [self.view removeGestureRecognizer:sender];
}

     (void)dismissButton:(UIButton *)button {
        [button removeFromSuperview];
        [[self.view.subviews lastObject] removeFromSuperview];

    }

    (void)catchTapForView:(UIView *)view {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = view.bounds;
        [button addTarget:self action:@selector(dismissButton:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:button];
    }

I want to make it so that the recognizer for the super view dismisses the subview, but not to interfere with the other taps on the super view.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:09:12+00:00Added an answer on June 11, 2026 at 5:09 am

    The easiest way to do what you describe is to overlay a transparent UIView that captures the touch. Simply remove it when touched.

    You can use the following code:

    - (void)dismissButton:(UIButton *)button {
        [button removeFromSuperview];
    }
    
    - (void)catchTapForView:(UIView *)view {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = view.bounds;
        [button addTarget:self action:@selector(dismissButton:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:button];
    }
    

    Call catchTapForView on your view. Do any additional handling in dismissButton.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario: I have a view that has some DataTemplate resources <DataTemplate x:Key=myDragCueTemplate> <Border Background=Blue
I want to launch a new fragment to view some data. Currently, I have
I have a table view and some buttons inside it. 4 buttons in one
I have some javascript on a view that makes an ajax call to my
I have some Javascript that dynamically adds rows/fields when you click the button, Add
I have a View controller displaying some information (not table views). I have an
I have a table view with some words, and i present flash-card style landscape
When I have a table view with some sections which have their own headers
I have a View where some input text to be added dynamica using jquery,
In my xib file I have some View. And I have PainView class (UIView).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.