Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make horizontal paging without vertical paging in UIScrollView

I am making digital comic now. My application has horizontal paging when without zooming. But when zooming, picture's height is over the screen height. So application has vertical paging.

But I don't need vertical paging. i want to make horizontal paging without vertical paging during zooiming.

Please teach me.

like image 364
kyoheialfaromeo2010 Avatar asked Dec 23 '22 02:12

kyoheialfaromeo2010


1 Answers

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.

like image 113
Ephraim Avatar answered Apr 28 '23 07:04

Ephraim