First of all, because of their own iOS development experience is limited, here will be implemented under the effect called Parallax Scrolling view, I do not know whether rigorous, and so on after experience, and then to update it.
First, the demand
Sometimes we may have a need to put a view above a uitableview (for ease of implementation, here is called TopView bar), want to achieve the effect is, when scrolling uitableview, let TopView also scroll up together When the TopView is scrolled to a certain position, the TopView is no longer scrolled, but only the UITableView is scrolled.
Second, the idea
1, the beginning of the idea is this, because TopView is required to scroll, so the TopView and UITableView added to a uiscrollview, According to Uiscrollview Contentoffset.y to determine whether to continue scrolling, that is, the default UITableView scrollenabled property is disabled, when Uiscrollview Contentoffset.y reached a certain value, disable Uiscrol The Scrollenabled property of LView enables the Scrollenabled property of UITableView. But after the experiment found that this approach will always have a variety of problems, the problem is not listed here, in short, after a toss-up, eventually abandoned the idea.
2, since the two added to a parent control uiscrollview is not feasible, it can only be analyzed from the UITableView itself. If you want to uitableview scrolling while the cell is in the UITableView view without being unloaded into the cache pool, can it be done by setting the Contentinset property of the UITableView? That is, like this:
In this case, if a topview is placed above the cell, changing the Y value of the TopView while the cell is scrolling will cause a false illusion: UITableView and TopView scroll up together, But actually just the cell and the TopView scroll together. That is, like this:
Third, the realization
So in the end it can be understood that:
So how much does the topview need to move up while the UITableView is rolling? How do you ensure that they are synchronized? Then you need to calculate how much is moved on the cell, how much the cell moves, and how much is topview, so that you can not strictly synchronize it? By subtracting the current offset from the initial offset of the UITableView, you get how much the cell has moved up. That is, like this:
When the offset of UITableView is 0 o'clock, it means that the TopView no longer needs to move up, and if you continue scrolling at this point, the cell will be unloaded into the cache pool because it exceeds the UITableView view boundary. This creates an illusion: TopView no longer scrolls, but UITableView is still rolling.
So the end result is this:
PS: This effect may be realized in your opinion is not what the problem, but really because of their own experience is limited, so still will toss the process of recording down, as a summary of it, do not like to spray.
Parallax scrolling view of iOS development