1
votes

I have a nested UIScrollView inside another one, both are horizontal.

The outer one contains multiple UIScrollViews, let's say one per page (of a document with multiple pages). The inner one can contain just a UIView that fits the screen or maybe some bigger UIView that should be scrolled too (tipically horizontally, but if the user pinches the screen, then he could scroll in both directions).

The problem occurs when I fastly scroll the document and the outer scroll view just decides to scroll its subviews, without letting the inner scroll views (those whose contentSize is bigger than the screen size) scroll at all. If I gently scroll the outer scroll view, it instead lets the inner one scroll too.

The desired behavior is that even if I fastly scroll the outer scroll view, it should scroll the inner one, until its content has been completely shown and only then let the outer scroll view scroll.

I tried overriding hitTest:withEvent: so that the outer scroll view should ask its currently visible UIScrollView subview if it should scroll or not, but this currently only works when scrolling forward. The problem is that I can't detect scrolling direction in hitTest:withEvent:, so I'm also thinking about moving this code into somewhere else, but I don't know if it's the correct way to go.

I'm sorry for all the "scroll" word in the sentences, but I don't know how to explain this in a better way

1
scrollview inside scrollview is not a recommended pattern by apple.It can bring unpredictable resultsLithu T.V
here developer.apple.com/library/ios/#documentation/WindowsViews/… they say it's supported. Unfortunately I can't see any other way to accomplish this. Moreover, I'm working on a big code base and it's unlikely that we're going to refactor this unless that's the only optionVik
It also says Note: This same-direction scrolling is supported, and there is a distinct behavior defined for the functionality, however that behavior is subject to change in future versions of iOS.Lithu T.V

1 Answers

0
votes

If the outer scrollView still animates movement, it will get all gestures instead of letting inner one handle them.

You could try using gestureRecognizer's requireGestureRecognizerToFail: method, so that panGestureRecognizer of the outer scroll view requires panGestureRecognizers of the outer scrollViews to fail. It might make the scrolling feel a bit laggy, and I'm not sure if that'll solve your problem but hey, doesn't hurt to try.