Rolling processing of UIScrollView nested UIScrollView

First, the overall effect diagram to illustrate

Rolling processing of UIScrollView nested UIScrollView

Page structure is a large scroll view three nested scroll view, at first in this effect, the Internet search and did not find a suitable solution, so in their own hands after the realization of share out, if you have this wonderful product demand in the development of and believe it will be a good solution, and they hope to help you! (as the examples, the effect is bad so few Diudiu ~)

First of all, we analyze the effect of several implementations:

1, UITableView+UIScrollView (nested three sub view)

2, UIScrollView+UIScrollView (nested three sub view)

These two schemes are realized based on UIScrollView, different point of view to build logic is different, I used in this paper is the effect of the second schemes to realize, first in the final treatment is the same. Here we will gradually analyze the entire implementation process

First step:

Create a parent view of the scrollView and sub scrollView, to build a basic interface effect (which I believe we can easily do)

After you have finished building the interface, you will find that the following areas of the parent view will not roll, like this

Rolling processing of UIScrollView nested UIScrollView

In the rolling parent view we will see if the drag over the parent view of frame, will appear at the bottom of the white, and scroll the list, pictures and details of these sub view parent will not also rolling, we need to do is to monitor the scroll position and do the deal when these views are rolling

Second step:

Set the scrollView agent to deal with, to monitor the scroll position the code in this scrollViewDidScroll agent method, we need to stay in the view when rolling to tab, can only continue to scroll view, so we only need to determine the scroll position is less than tab when the head with the view of rolling rolling in the parent view the child view in the rolling, need to always set

.

[scrollView setContentOffset:CGPointZero];

(note that it is not possible to add animated:YES here).

.

When we scroll to the parent view, we only need to judge if the scroll position exceeds the tab is set to tab position:

.

If (self.journeyScrollView.contentOffset.y > = self.titleView.y) {

[self.journeyScrollView setContentOffset:CGPointMake (0, self.titleView.y)];

}

.

In order to understand that the parent view shift caused by a child view scroll to the top is not automatically returned, we need to judge the location of the parent view in the scrollViewDidEndDragging proxy method

.

If (self.journeyScrollView.contentOffset.y < 0) {

[self.journeyScrollView setContentOffset:CGPointZero

Animated:YES];

}

.

The logical view of a nested scroll is done. If you still have doubts, you can look at an example of Demo:https://github.com/lvXiaoPeng/LYEmbedScrollView in this article.

Finally, if you have a better implementation of the principles and solutions, I hope you can tell me to learn together!

First the overall effect diagram is given in the paper page structure is a large scroll view three nested scroll view, at first in this effect, the Internet search and did not find a suitable solution, so in their own hands after the realization of share out, if you encounter this the wonderful demand for products in development, believe it is a good solution, and they hope to help you! (as the examples, the effect is bad so few Diudiu ~)

最后,如果你有更好的实现原理和解决方案,希望能告诉我,共同学习!