View with continuous scroll; both horizontal and vertical

后端 未结 4 558
迷失自我
迷失自我 2020-11-28 03:02

I have been struggling with this assignment for quite some time now. What I would like to develop is a scrollview or collectionview which scrolls continuously both vertical

4条回答
  •  不知归路
    2020-11-28 03:42

    Resetting the contentOffset probably is the best solution figured out so far.

    A few steps should be taken to achieve this:

    1. Pad extra items at both the left and right side of the original data set to achieve larger scrollable area; This is similar to having a large duplicated data set, but difference is the amount;
    2. At start, the collection view’s contentOffset is calculated to show only the original data set (drawn in black rectangles);
    3. When the user scrolls right and contentOffset hits the trigger value, we reset contentOffset to show same visual results; but actually different data; When the user scrolls left, the same logic is used.

    So, the heavy lifting is in calculating how many items should be padded both on the left and right side. If you take a look at the illustration, you will find that a minimum of one extra screen of items should be padded on left and also, another extra screen on the right. The exact amount padded depends on how many items are in the original data set and how large your item size is.

    I wrote a post on this solution:

    http://www.awsomejiang.com/2018/03/24/Infinite-Scrolling-and-the-Tiling-Logic/

提交回复
热议问题