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 do开发者_运维问答n't need vertical paging. i want to make horizontal paging without vertical paging during zooiming.
Please teach me.
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 equalscrollHorizontal.contentSize.height
(otherwise, you will end up with vertical paging)scrollVertical
: first, you will have one of this for each page. The frame width andcontentSize.width
should match and make sense w.r.t. the width of a page (in yourscrollHorizontal
). You should of course have the frame height be no more thanscrollHorizontal.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.
There technically is no such thing as vertical paging, only horizontal as of right now for the standard API. Up/down is scrolling, and paging left/right is a little different.
You should be able to disable vertical scrolling within Interface Builder after selecting the uiscrollview and editing its properties within the inspector window.
You can dynamically set the pagingEnabled
to NO
when the user zooms in, and then set it back to YES
when they zoom out.
Check out the docs for UIScrollViewDelegate
to learn how to detect zooming.
精彩评论