2
votes

I have view controller with following view hierarchy:

UIView
 '- UIScrollView
      '- UIWebView
      '- UIWebView
      '- ... more UIWebViews

UIScrollView has paging enabled and each page contains one UIWebView. UIScrollView occupies entire screen, UIWebView as well.

Now my problem is that I need to detect touches on entire screen. I guess that UIScrollView somehow eats most of those (and since UIWebView contains scroll view as well, things got even more complicated).

I tried subclassing each of those views and tried both touchesBegan and tap gesture recognizer but nothing. All I was able to get was very unreliable gesture recognizer on UIWebView, it worked once in 20 taps, very random and very weird.

How should I solve this? I need touchesBegan and touchesEnded or tap gesture.

2

2 Answers

2
votes

I think you'll need to find an alternative way of building your UI. Apple explicitly recommend against embedding scroll views inside scroll views:

You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.

Without knowing what you're trying to achieve it's difficult to be able to suggest a valid alternative. Tabs? A swipe gesture at the bottom of the screen? Links inside the webviews?

0
votes

You can do that, but you need to be careful with the touch events so that scrollview does not handle touches intended for webview.

Import line on the code below is [[[wv1 subviews] lastObject] setScrollEnabled:NO];

for (NSString *link in links) {
    UIWebView *wv1 = [[UIWebView alloc] initWithFrame:frame];
    NSURL *aurl = [site getUrl:link local:YES];
    [wv1 loadRequest:[NSURLRequest requestWithURL:aurl]];
    [[[wv1 subviews] lastObject] setScrollEnabled:NO];
    [scrollView addSubview:wv1];
    [wv1 release];  
}