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 7848571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:15:09+00:00 2026-06-02T18:15:09+00:00

I have a UIGestureRecognizer that I want to work on two different UIViews, both

  • 0

I have a UIGestureRecognizer that I want to work on two different UIViews, both of which are in the same view hierarchy of a UiViewController. The action of the UIGestureRecognizer is about the same on each, so I would like for the same function to be called (it will, obviously) and I will tell at runtime which of the UIViews I am dealing with. But how? I cannot see that the UIGestureRecognizer is carrying the object information with it. Am I missing the line in the documentation or does the gestureRecognizer not know which object that it has been attached to that it is being called on? Seems like the point of the language would be that it would know.

Alternatively, maybe I am misunderstanding the intent of the class and I should not:

UITapGestureRecognizer *dblTap = 
[[UITapGestureRecognizer alloc] initWithTarget: self 
                                        action: @selector(handleDblTap:)];   
[viewA addGestureRecognizer: dblTap]; 
[viewB addGestureRecognizer: dblTap];

and then expect to be able to:

-(void)handleDblTap: (UIGestureRecognizer *)gestureRecognizer
{
     if (viewA)...

If in fact UIGestureRecognizer does not support being attached to multiple objects simultaneously, then, if you know why it does not support this, could you educate me? Thanks for the help.

  • 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-02T18:15:12+00:00Added an answer on June 2, 2026 at 6:15 pm

    The standard is one view per recognizer. But you can still efficiently use one handler method.

    You would instantiate the recognizers like so:

    UITapGestureRecognizer *dblTapViewA = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDblTap:)];   
    [viewA addGestureRecognizer: dblTapViewA]; 
    
    UITapGestureRecognizer *dblTapViewB = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDblTap:)];
    [viewB addGestureRecognizer: dblTapViewB];
    

    Then your handler method could look something like:

    -(void)handleDblTap:(UITapGestureRecognizer *)tapRec{
        if (tapRec.view == viewA){
            // double tap view a
        } else if (tapRec.view == viewB) {
            // double tap view b
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIViewController that has both a UITable and a UIView on it.
I have an iPad app where I have a view controller that is the
I currently have this in my code tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(updateLeftLabel:)]; which
I have 3 UIGestureRecognizers attached to a view: one finger double tap, two fingers
I have a UITableView which I present in a UIPopoverController . The table view
Does anyone have any idea why Apple designed UIGestureRecognizer the way that default state
I have dynamically created view ,inside that dynamically created buttons.while clicking the buttons I
I have a number of classes and want to add a UIGestureRecognizer to their
I have a simple (view-based) application. I want on tapping on custom UIView my
I have 2 GestureRecognizers that when triggered at the same need to trigger an

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.