IPhone development-the easiest way to check the Touch/UITapGestureRecognizer event on UIWebView

Source: Internet
Author: User

I have a program that needs to check whether UIWebView has touch actions. Unfortunately, touchesBegan and other events on UIWebView cannot be detected. I checked on the Internet and found many solutions, such as adding a transparent UIView to UIWebView, resetting the sendEvent of UIWindow, or resetting the hitest method of UIWebView. either, the solution is not perfect, either it is too complicated. After the experiment, the method I used is the simplest (or I don't have time to write it here). Of course, I only need to check that there is a touch action on UIWebView. My method is to use UITapGestureRecognizer. There are two key points. See my code (my code is in a UIViewController ):

[Cpp] UITapGestureRecognizer * singleTap = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (handleSingleTap :)];
[Self. view addGestureRecognizer: singleTap];
SingleTap. delegate = self;
SingleTap. cancelsTouchesInView = NO;
[SingleTap release];
UITapGestureRecognizer * singleTap = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (handleSingleTap :)];
[Self. view addGestureRecognizer: singleTap];
SingleTap. delegate = self;
SingleTap. cancelsTouchesInView = NO;
[SingleTap release];
The third line is the first key, that is, the delegate of UITapGuestureRecognizer must be set (generally we directly use initWithTarget without setting its delegate ).

The second key is to return YES in the following delegate method. Www.2cto.com

 

[Cpp]-(BOOL) gestureRecognizer :( UIGestureRecognizer *) gestureRecognizer plugin :( UIGestureRecognizer *) otherGestureRecognizer
{
Return YES;
}
-(BOOL) gestureRecognizer :( UIGestureRecognizer *) gestureRecognizer author :( UIGestureRecognizer *) otherGestureRecognizer
{
Return YES;
}
By doing this, your UIWebView can respond to the touch event. You can use different UIGestureRecognizer to meet your different requirements. (Complete the handleSingleTap Method on your own ).

From the column zcl316369

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.