In an iOS app, I have a UIWebView which I use to display some contents and to dismiss this UIWebView I use the following mechanism:
I put a DoubleTapView (subclass of UIView) on top of the UIWebView.
This DoubleTapView catches the double-tap events and executes adequate code to dimiss itself as well as the UIWebView. Up to this point it works fine.
Here is the problem: All the events that the UIWebView is interested in (scrolling the contents, tapping links ..etc..) don't go through; they are blocked by the DoubleTapView. How can I solve this?
In fact for what I just described I could have used a UIView instead of a DoubleTapView. But I intended to subclass UIView with DoubleTapView. And then implement: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; or - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event; to solve my problem, but I must be doing something wrong, because it does not work (at list the way I did).
Here is some code I wrote to put the parts together:
webView=[[UIWebView alloc] initWithFrame:varFrame];
webView.delegate=self;
quitGesture=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(quitWeb:)];
quitGesture.numberOfTapsRequired=2;
varFrame.origin=CGPointZero;
quitSensor=[[DoubleTapView alloc] initWithFrame:varFrame];
quitSensor.userInteractionEnabled=YES;
[quitSensor addGestureRecognizer:quitGesture];
[webView addSubview:quitSensor];
and here is what I tried when implementing the methods for DoubleTapView:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[[self superview] touchesBegan:touches withEvent:event];
}
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
[[self superview] motionBegan:motion withEvent:event];
}