How to do horizontal paging without vertical paging in UIScrollView

I'm doing a digital comic now. My application has horizontal paging when without scaling. But when scaling, the height of the image exceeds the height of the screen. Thus, the application has vertical paging.

But I do not need vertical paging. I want to do horizontal paging without vertical paging during zooiming.

Please teach me.

+4
source share
3 answers

It is really easy. As your friend suggested, you will need at least 2 UIScrollView . For horizontal (i.e. Paging) you will need a UIScrollView , and you will need one UIScrollView for each page. The key points are (call them scrollHorizontal and scrollVertical ):

  • scrollHorizontal.frame.height should equal scrollHorizontal.contentSize.height (otherwise you will scrollHorizontal.contentSize.height into vertical paging)
  • scrollVertical : first, you will have one of them for each page. The frame width and contentSize.width should match and it makes sense to wrt the page width (in your scrollHorizontal ). Of course, you should have a frame height of no more than scrollHorizontal.contentSize.height .

Code example:

 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 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 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.

+13
source

There is technically no such thing as vertical paging, only horizontal, as it is now, for the standard API. Up / down scrolls, and swap left / right is slightly different.

You should be able to disable vertical scrolling in Interface Builder after selecting uiscrollview and editing its properties in the inspector window.

-1
source

You can dynamically set pagingEnabled to NO when the user pagingEnabled out and then returns it to YES when they zoom out.

Check out the docs for UIScrollViewDelegate to find out how to detect scaling.

-1
source

Source: https://habr.com/ru/post/1312462/


All Articles