It's really simple. As your friend suggested, you will need AT LEAST two UIScrollView
. You will need one UIScrollView
for the horizontal (i.e. paging), and you will need one UIScrollView
for each page. The key points are (let's name them scrollHorizontal
and scrollVertical
):
scrollHorizontal.frame.height
must equal scrollHorizontal.contentSize.height
(otherwise, you will end up with vertical paging)
scrollVertical
: first, you will have one of this for each page. The frame width and contentSize.width
should match and make sense w.r.t. the width of a page (in your scrollHorizontal
). You should of course have the frame height be no more than scrollHorizontal.contentSize.height
.
Sample code:
UIScrollView scrollHorizontal = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
scrollHorizontal.pagingEnabled = YES;
scrollHorizontal.directionalLockEnabled = YES; // not needed but helpful
// Now let's create each page
UIScrollView *scrollPage1 = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[scrollPage1 addSubview:theContentViewForPage1];
scrollPage1.contentSize = CGSizeMake(self.view.bounds.size.width, theContentViewForPage1.bounds.size.height);
// Add page to scrollHorizontal
[scrollHorizontal addSubview:scrollPage1];
[scrollPage1 release];
//...add more pages (REMEMBER to set the scroll view's frame.origin.x accordingly for each additional page)
// Set the scrollHoriztonal content size
scrollView.contentSize = CGSizeMake(self.view.bounds.size.width*NUMBER_OF_PAGES, self.view.bounds.size.height);
// Now add the scrollview to self.view; or even self.view = scrollHorizontal, etc.