I am showing a document in a UIWebView. I want to place an access point above the document to trigger an action when it is being listened, but I also want to support the default UIWebView behavior to automatically scale the document when it is double-clicked. I cannot figure out how to respond to single clicks, allowing the UIWebView to respond to double clicks.
First, I set the access point as a transparent UIButton with the action, but double-clicking on the hotspot causes the hotspot action to be called twice. So I deleted the action with the button and added a one-touch gesture, and 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 action of a regular button. But then I created a double-touch gesture and set it up to block a one-touch gesture using 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 setting, a single click on a hot spot calls singleTapAction and double click on a hot spot calls zoomWebView (native method). This is good because singleTapAction is no longer called twice, but bad because UIWebView no longer responds to double-clicking.
UIWebView, UITapGestureRecognizer, touchhesBegan touchesEnded UIWebView. , , , UIWebView . , iOS , UIView, UIKit.
, , ? , . , .
, UIWebView - "" - . " ", - "grandparent", .