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

  • Home
  • SEARCH
  • 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 854119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:52:18+00:00 2026-05-15T07:52:18+00:00

I am attempting to get a UIGestureRecognizer working with a UIWebview which is a

  • 0

I am attempting to get a UIGestureRecognizer working with a UIWebview which is a subview of a UIScrollView. This sounds odd but when I have the numberOfTouchesRequired set to 2 the selector fires, but when numberOfTouchesRequired is set to one the selector doesn’t fire.

Here is my code:

UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(select1:)];
    tap1.numberOfTouchesRequired = 2;
    tap1.numberOfTapsRequired = 1;
    tap1.delegate = self;
    [self.ans1WebView addGestureRecognizer:tap1];
    [tap1 release];

- (void) select1:(UILongPressGestureRecognizer *)sender {
    //Do Stuff
}

I’ve confirmed this by using the Apple sample for UIGestureRecognizer and inserting a webview in their nib. Their tap code works everywhere but inside the area of the webview.

  • 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-05-15T07:52:18+00:00Added an answer on May 15, 2026 at 7:52 am

    From what I have seen, UIWebView does not play well with others. For gesture recognizers, you could try returning YES from:

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
    

    I had to be backwards compatible with 3.0 so I ended up doing all the gesture handling with Javascript inside the UIWebView. Not a good solution, but it worked for my needs. I was able to capture a long press on an element, as well as tap, swipe, pinch and rotate. Of course, I was using only local content.

    Edit:

    You can look in PhoneGap for an example of sending messages to the delegate of the UIWebView. In a nutshell, you use document.location = "myscheme:mycommand?myarguments" then parse out the command and arguments from this delegate callback:

    -(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
      if ( [[[inRequest URL] absoluteString] hasPrefix:@"myscheme:"] ) {
        //.. parse arguments
        return NO;
      }
    }
    

    You can see in the PhoneGap code that they set up a queue and timer to send the messages. Depending on your usage, you may need to do the same thing. There are other questions on SO on this topic.

    Here is the Event Handling documentation. In my case I added event listeners to document from <body onload="myloader();">

    function myloader() {
        document.addEventListener( 'touchcancel' , touch_cancel , false );
        document.addEventListener( 'touchstart' , touch_start , false );
        document.addEventListener( 'touchmove' , touch_move , false );
        document.addEventListener( 'touchend' , touch_end , false );
    };
    

    The actual event handling depends a lot on your needs. Each event handler will receive a TouchEvent with a touches property where each item is a Touch. You can record the start time and location in your touchstart handler. If the touches move to far or the wrong amount of time passes it is not a long touch.

    WebKit may try to handle a long touch to start a selection and copy. In your event handler you can use event.preventDefault(); to stop the default behavior. I also found the -webkit-user-select:none css property handy for some things.

    var touch = {};
    function touch_start( event /*TouchEvent*/ {
      event.preventDefault();
      touch = {};
      touch.startX = event.touches.item(0).pageX;
      touch.startY = event.touches.item(0).pageY;
      touch.startT = ( new Date() ).getTime();
    }
    

    This is only the second project I have used javascript with. You can find better examples elsewhere.

    As you can see this is no quick answer to your problem. I am pretty happy with the results I got. The html I was working with had no interactive elements beyond a link or two.

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

Sidebar

Related Questions

I'm attempting to get my first ASP.NET web page working on windows using Mono
I am attempting to get nhibernate working in medium-trust. What I found said that
I am attempting to get a gem I installed working in a Rails application.
While attempting to get an old svn dump of a project under git control,
I am attempting to get a DropDownList to AutoPostBack via an UpdatePanel when the
I am attempting to get the information from one table (games) and count the
I get the following error when attempting to install RubyGems . I've tried Googling
When attempting to compile my C# project, I get the following error: 'C:\Documents and
From time to time I get a System.Threading.ThreadStateException when attempting to restart a thread.
I'm attempting to use Assembly.GetType(MyCompany.Class1.Class2) to dynamically get a type from a string. Assembly.GetType(MyCompany.Class1);

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.