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:
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate: (BOOL)decelerate{
scrollView.bounces = NO;
}
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:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGFloat scrollViewHeight = scrollView.frame.size.height;
CGFloat scrollContentSizeHeight = scrollView.contentSize.height;
CGFloat scrollOffset = scrollView.contentOffset.y;
CGFloat offset = scrollContentSizeHeight - (scrollOffset + scrollViewHeight);
if (offset <= 0)
[self.parentView setContentOffset:CGPointMake(self.parentView.contentOffset.x, self.parentView.contentOffset.y + diffOffset) animated:YES];
}
Where diffOffset
is the distance you want the parentScroll to scroll.
You may prefer more advanced workaround.
For example you can implement
scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
so you know what is the velocity
of the scroll, comparing targetContentOffset
to scrollContentSizeHeight
and scrollViewHeight
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
and animationTime
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.