Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can have nested scrollviews to get scrolling working in both directions. Let's have a vertical scroller inside a horizontal scroller (though you can very well do it the other way round too), so views 3 and 1 get into a vertical scrollview, which in turn gets inside a horizontal scroller along with view 2. </p> <p>You could create such a view hierarchy in code (probably in the main viewcontroller's <code>viewDidLoad</code>). The following snippet assumes view1, view2 and view3 as webviews.</p> <pre><code>CGRect bounds = self.view.bounds; // main guy is a horizontal scroller UIScrollView *hScrollView = [[UIScrollView alloc] initWithFrame:bounds]; hScrollView.contentSize = CGSizeMake(bounds.size.width * 2, bounds.size.height); hScrollView.delegate = self; [self.view addSubview:hScrollView]; // the horizontal scroller contains a vertical scroller UIScrollView *vScrollView = [[UIScrollView alloc] initWithFrame:bounds]; vScrollView.contentSize = CGSizeMake(bounds.size.width, bounds.size.height * 2); vScrollView.delegate = self; [hScrollView addSubview:vScrollView]; // add view3 and view1 to the vertical scroller UIWebView *view3 = [[UIWebView alloc] initWithFrame:bounds]; [view3 loadHTMLString:@"&lt;h1&gt;3&lt;/h1&gt;" baseURL:nil]; [vScrollView addSubview:view3]; UIWebView *view1 = [[UIWebView alloc] initWithFrame:CGRectOffset(bounds, 0, bounds.size.height)]; [view1 loadHTMLString:@"&lt;h1&gt;1&lt;/h1&gt;" baseURL:nil]; [vScrollView addSubview:view1]; vScrollView.contentOffset = CGPointMake(0, bounds.size.height); // add view2 to the horizontal scroller UIWebView *view2 = [[UIWebView alloc] initWithFrame:CGRectOffset(bounds, bounds.size.width, 0)]; [view2 loadHTMLString:@"&lt;h1&gt;2&lt;/h1&gt;" baseURL:nil]; [hScrollView addSubview:view2]; // enable paging in both directions hScrollView.pagingEnabled = TRUE; vScrollView.pagingEnabled = TRUE; </code></pre> <p>That would have you scrolling in both directions but that would also let you scroll-right from view3 to view2. If you want to prevent that, you should disable scrolling on <code>hScrollView</code> whenever the <code>vScollView</code> is showing view3. You can do that in <code>scrollViewDidEndDecelerating:</code> in the delegate of <code>vScrollView</code>. Something like:</p> <pre><code>-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { if (scrollView == self.verticalScrollView) { self.horizontalScrollView.scrollEnabled = (self.verticalScrollView.contentOffset.y &gt; self.view.bounds.origin.y); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload