I want to implement a paging UIScrollView that will scroll in both directions (vertically, and horizontally). The default behaviour of UIScrollView is to be one, or the other. Not both.
Is it possible to implement a UIScrollView that would allow paging in both directions? For example, the user would be able to scroll left and up for the previous page with paging in UIScrollView, right and down for the next page.
I can use UIScrollView to implement scrolling horizontally with paging but I can’t see how UIScrollView can be scrolled in both directions while paging. How could I implement this behaviour? UIScrollView ? or CAScrollLayer? or anything else?
Any suggestion are appreciated.
You seem to be talking about two different things here: scrolling and paging.
Scrolling is just flicking around to move the screen’s viewport over a view that is larger than the screen itself. Normally you set this up by giving a
UIScrollViewa subview that is larger than it, and setting theUIScrollView‘scontentSizeto the size of the larger thing.There’s nothing magic about it. If
contentSizeis taller than theUIScrollView‘s size, the scroll view will scroll vertically. IfcontentSizeis wider, it will scroll horizontally. IfcontentSizeis both taller and wider, then you’ll scroll both vertically and horizontally.Paging is a different matter. To know how to make it so “you can scroll left and up for the previous page”, we’ll need to know what a page looks like in your program, how it’s represented, etc. From the small description you’re giving, I think
UIScrollViewprobably isn’t the way to go. Instead, look intoUIPanGestureRecognizerand some sort of animated transition between views?But if that doesn’t help, you’ll need to give us some more details to work with.