Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView's inside UIScrollView consuming touch events

I have multiple custom UIWebView's as subviews within a UIScrollView. I have implemented the touch methods within the UIViewController for the UIWebView's, but these methods are not being called.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { }
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { }
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { }

I have read elsewhere and it says that the UIScrollView will consume the events. This makes sense, but should the UIWebView's not receive the touch event before the UIScrollView itself? What is probably happening, is that the UIWebBrowserView (a subview of the UIWebView) is consuming the events. This class can't be subclassed however, and so I can't send the events up the superview chain to the UIScrollView. I have read on the Apple iOS Documentation that one shouldn't ever place a UIWebView inside a UIScrollView, but I need to do so for my purposes.

So my question is: how can my custom UIWebView's (that are subviews of a UIScrollView) receive touch events?

My controllers and views are set up as follows:

HomeViewController.h /.m /.xib
HomeView.h /.m (is a UIScrollView)
DashboardViewController.h /.m /.xib (custom UIWebView's)

HomeViewController is loaded from a Nib file that contains a custom view: HomeView. DashboardViewController is loaded from a Nib file. It contains a few labels, sliders, etc. (note that there is no custom view here - I am not subclassing UIView here).

HomeViewController dynamically loads several DashboardViewControllers and adds its view to the HomeView.

DashboardViewController *dashboardViewController = [[DashboardViewController alloc] initWithNibName:@"DashboardViewController" bundle:[NSBundle mainBundle];
[homeView addSubview:dashboardViewController.view];
like image 976
mdupls Avatar asked Nov 04 '22 18:11

mdupls


1 Answers

You are probably looking for canCancelContentTouches.

scrollView.canCancelContentTouches = NO;
like image 200
Deepak Danduprolu Avatar answered Nov 11 '22 06:11

Deepak Danduprolu