I have a child scroll view contained within a parent scroll view (not a direct child). What I want is for the parent scroll view to start scrolling in the same direction as soon as the child scroll view reaches the end of its content.
This kind of works out of the box, but not really. Right now I have to lift my finger to make the parent scroll view start scrolling after the child has reached the end.
Any thoughts on this?
EDIT:
An example of what I'm looking for can be seen in Snapchat by swiping right in a table view cell to reveal the chat controller.
Not sure if I correctly understand what does not being a direct child mean. But iOS should do it automatically for you as soon as you reached the end of scroll of child view it should let you scrolling parent scroll.
For this you need to implement for the child:
scrollView.bounces = NO
does not let scrollView to jump back on end scroll. So it's just stick at the position it stops scrolling.And then you need to trigger parent scrolling from the
scrollViewDidScroll
method for the child.Something similar to:
Where
diffOffset
is the distance you want the parentScroll to scroll.You may prefer more advanced workaround.
For example you can implement
so you know what is the
velocity
of the scroll, comparingtargetContentOffset
toscrollContentSizeHeight
andscrollViewHeight
should let you know that this particular scroll is about to end dragging reaches the end of scroll view content.And you can calculate
diffOffset
andanimationTime
more accurately.It could be nice to block scrolling for child view when it's not fully visible within parent scroll, so the scrolling ability appears only when you scroll up until certain position.