1
votes

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.

1

1 Answers

0
votes

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.