Is it possible to implement a paging UIScrollView in both directions? - ios

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 UIScrollView a subview that is larger than it, and setting the UIScrollView's contentSize to the size of the larger thing.
There's nothing magic about it. If contentSize is taller than the UIScrollView's size, the scroll view will scroll vertically. If contentSize is wider, it will scroll horizontally. If contentSize is 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 UIScrollView probably isn't the way to go. Instead, look into UIPanGestureRecognizer and 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.

Related

Horizontal scroll view not scrolling

I've just vertical scrolling a few times in the past, but now I'm trying to implement horizontal scrolling but when I run it it doesn't scroll.
What is the problem with it?
P.S. is it possible to design and layout views using a storyboard for scrolling? In this example the blue view is still visible within the screen representation, so its ok to deal with, but suppose I wanted to add another view which is further to the right and thus not visible within the screen representation? Is there anyway of visually designing a scroll view where you can see all the entirity within the storyboard what it will look like?
You don't have a trailing constraint on the scroll view's direct subview, so the scroll view cannot compute the correct contentSize.
Also, it's easier to understand the constraints in the document outline if you give each view a unique label. You have two views labelled “View” so it's difficult to be sure which constraints connect to which “View”.

How to handle an UIScrollView in an UIScrollView

I want to use an UIScrollView in an UIScrollView. I think it would be clearer with a
picture
The black border is the border of the screen, the purple is the first UIScrollView and the blue is the second UIScrollView. The arrows show the direction of the scroll.
When I try to put the second UIScrollView in the first with a different scrolling direction, the second show the content twice... I made a video
I have created design for you to explain how to add scroll view inside scroll view.
Here see the following image with constraints.
Note: This is static view not dynamic, This is create to clear concept of ScrollView inside ScrollView. If you are planning to make ScrollView with design then you need to do some more study on AutoLayout with ScrollView.

How to make UITableView scroll both horizontally and vertically

I don't know How to make UITableView scroll both horizontally and vertically as Kickstarter ios app. Would you please explain briefly how can they do both way? Thank you.
Tab scroll horizontally
Tab scroll vertically
P/s: sorry, my reputation point is so low that i cannot embed the image.
There are actually two different levels to the two directions of the "table view". The vertical scrolling is some sort of paginated table/scroll/collection view; this can be accomplished using a table view, a scroll view, or a collection view. Here's a great answer on how to do vertical paging in a scroll view. Within each page, it looks like a UICollectionView.
That is simply a vertical UIScrollView with paging enabled. Each page is populated with a horizontal UICollectionView.

UIScrollview control scrolling

I have an iOS project which needs to "control" the UIScrollview's scrolling. UIScrollview needs to know current scroll position, also needs to limit scroll, and "transfer" the scroll to scroll the UITableView inside it.
I tried to google, apple dev, ... but no luck :(
I have to handle UIPanRecognizer by myself, but it isn't "smooth" like UIScrollview default scrolling (scroll accelerator).
Anyone have an idea?

UIScrollView within UIScrollView within UIScrollView

I have a multidirectional UIScrollView within a horizontal UIScrollView within a vertical UIScrollView. When I reach the horizontal content limit of the innermost scrollView, the containing horizontal scrollview begins scrolling just as I want.
But when I reach the vertical content limit of the innermost scrollView, I do not get any action on the top level vertical scrollView.
If all vertical content is visible at innermost level (so no vertical scrolling is possible), then the top level vertical scrollview takes over fine. Any clues on how to fix this?
I get this same behavior with Apple "PhotoScroller" sample code if I embed their photo paging scrollView in a vertical scrollView. If the photo is not zoomed, then both the horizontal and vertical scrollviews will work. If the photo is zoomed but panning stops because it has hit the horizontal or vertical limit, then only the horizontal scrollview works.
This is using an older version of the sample code that implements the photo paging as a UIScrollView rather than UIPageViewController. With current UIPageViewController version, paging is not possible when the photo is zoomed.
To answer my own question, I used gestureRecognizerShouldBegin: delegate to determine whether the innermost scrollView was at a boundary when the pan gesture began. If so, I responded to shouldRecognizeSimultaneouslyWithGestureRecognizer:
delegate to enable the UIPanGestureRecognizer on both the inner scrollView and the vertical scrollView. This allowed a single gesture to scroll both simultaneously. Then, I over-rode setContentOffset on both scrollViews to suppress the scrolling on the wrong one.
I think a better answer is probably to replace the UIPanGestureRecognizer on the inner UIScrollView with a custom gesture recognizer that cancels itself when started at a boundary and dragging past the boundary. But, I could not get that to work.
Still not clear to me why the horizontal version of this just worked automatically. Perhaps there is some special case handling in the UIScrollViewPanGestureRecognizer to handle horizontal case, or interaction with immediate superView.

Resources