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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:19:46+00:00 2026-06-08T05:19:46+00:00

I’m displaying a document in a UIWebView. I want to place a hotspot over

  • 0

I’m displaying a document in a UIWebView. I want to place a hotspot over the document to trigger an action when it is tapped, but I also want to maintain the default UIWebView behavior of auto-zooming the document when it is double-tapped. I can’t figure out how to respond to the single-taps while letting the UIWebView respond to the double-taps.

I first set up the hotspot as a transparent UIButton with an action, but double-tapping the hotspot resulted in the hotspot action being called twice. So I removed the action from the button and attached a single-tap gesture instead:

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapAction:)];
singleTap.numberOfTapsRequired = 1;
singleTap.delegate = self;
[self.hotspot addGestureRecognizer:singleTap];
[singleTap release];

This works the same as the normal button action. But then I created a double-tap gesture, and configured it to block the single-tap gesture with requireGestureRecognizerToFail:

UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(zoomWebView:)];
doubleTap.numberOfTapsRequired = 2;
doubleTap.delegate = self;
[self.hotspot addGestureRecognizer:doubleTap];
[doubleTap release];

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapAction:)];
singleTap.numberOfTapsRequired = 1;
[singleTap requireGestureRecognizerToFail:doubleTap];
singleTap.delegate = self;
[self.hotspot addGestureRecognizer:singleTap];
[singleTap release];

- (void)zoomWebView:(UITapGestureRecognizer *)gesture {
    NSLog(@"double tap");
}

With this setup, a single-tap on the hotspot calls singleTapAction and a double-tap on the hotspot calls zoomWebView (a custom method). This is good because singleTapAction is no longer called twice, but bad because the UIWebView no longer responds to the double-tap.

I tried forwarding the double-tap event from my doubleTap gesture to the UIWebView by subclassing UITapGestureRecognizer, overriding the touchesBegan and touchesEnded methods, and sending their arguments on to the corresponding methods of the UIWebView. When I did that, I could see that my subclass was receiving the events, but the UIWebView didn’t respond to the forwarded events. This is to be expected because the Event Handling Guide for iOS says that we can only forward events to custom subclasses of UIView, not to UIKit framework objects.

Is there a way to prevent my single-tap gesture from responding to double-taps that doesn’t divert the double-tap events? This seems like a basic requirement, but I can’t see a straightforward way to do it. I read about and experimented with UIGestureRecognizer’s touch delivery properties, but no combination of values stopped the single-tap gesture from consuming the double-tap gesture.

By the way, the relationship between the hotspot and the UIWebView in my view hierarchy is that of “cousins” — they are subviews of two sibling views. If I add the gesture recognizers to hotspot view, the web view or their “grandparent” view, I get the same results.

  • 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-08T05:19:48+00:00Added an answer on June 8, 2026 at 5:19 am

    Okay, I found a solution in two parts:

    1) I had to add my gestures to a parent view of the UIWebView. Unmatched events don’t travel through overlapping objects in a view from layer to layer as I was imagining. Instead, they travel through the hierarchy of views from child to parent. So as long as I was adding my double-tap gesture to a sibling or “cousin” view of the UIWebView, it was never going to proceed on to the web view. This means that I can’t use buttons or views laid out in Interface Builder to determine multiple hotspot areas. Instead, I have to redirect all single-tap events to one method and then look at the touch positions to determine what action to trigger.

    2) I had to add the gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: method to my view controller (the delegate of my gestures) and return YES. This allows my single-tap gesture to respond even when I’m displaying HTML, text or image content in the UIWebView, which implements its own gesture for these content types. I learned this part from this answer.

    With these changes, I understand the hierarchy of events to be:

    • Single-tap web view: my single-tap gesture on the web view’s parent view responds; the web view’s single-tap gesture also responds if applicable because simultaneous gestures are enabled

    • Double-tap web view: my double-tap gesture on the web view’s parent view responds (but doesn’t do anything); my single-tap gesture does not respond because it is configured to only respond if the double-tap fails; the web view’s double-tap event also responds because it is part of the view hierarchy (it seems that the double-tap functionality of the web view does not use a gesture because otherwise it would have take precedence over my own gesture in my original setup)

    With that explanation out of the way, here’s some working code:

    - (void)viewDidLoad {
        UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapWebView:)];
        doubleTap.numberOfTapsRequired = 2;
        doubleTap.delegate = self;
        [self.webViewParent addGestureRecognizer:doubleTap];
        [doubleTap release];
    
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapWebView:)];
        singleTap.numberOfTapsRequired = 1;
        [singleTap requireGestureRecognizerToFail:doubleTap];
        singleTap.delegate = self;
        [self.webViewParent addGestureRecognizer:singleTap];
        [singleTap release];
    }
    
    - (void)doubleTapWebView:(UITapGestureRecognizer *)gesture {
        NSLog(@"double-tap");
        // nothing to do here
    }
    
    - (void)singleTapWebView:(UITapGestureRecognizer *)gesture {
        NSLog(@"single-tap");
        CGPoint touchLocation = [gesture locationInView:self.webViewParent];
        float x = touchLocation.x;
        float y = touchLocation.y;
        CGRect frame = self.webViewParent.frame;
        if (y < frame.size.height * .33) {
            NSLog(@"top");
        } else if (y > frame.size.height * .67) {
            NSLog(@"bottom");
        } else if (x < frame.size.width * .33) {
            NSLog(@"left");
        } else if (x > frame.size.width * .67) {
            NSLog(@"right");
        } else {
            NSLog(@"center");
        }
    }
    
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
        return YES;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
i want to parse a xhtml file and display in UITableView. what is the
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.