First of all, I recommend using a UITableView so that you can keep low memory usage. The approach that I successfully used in the project is as follows:
Duplicate the contents of your cells, I mean, if you have 5 elements this way:
| 1 | 2 | 3 | 4 | 5 |
At the end of the table, you should add the same thing (in the form of a table with a reusable engine, which is not very important) to look like this:
| 1 | 2 | 3 | 4 | 5 | 1 | 2 | 3 | 4 | 5 |
- 2. modify scrollViewDidScroll as follows:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView { if (scrollView == _yourScrollView) { CGFloat currentOffsetX = scrollView.contentOffset.x; CGFloat currentOffSetY = scrollView.contentOffset.y; CGFloat contentHeight = scrollView.contentSize.height; if (currentOffSetY < (contentHeight / 6.0f)) { scrollView.contentOffset = CGPointMake(currentOffsetX,(currentOffSetY + (contentHeight/2))); } if (currentOffSetY > ((contentHeight * 4)/ 6.0f)) { scrollView.contentOffset = CGPointMake(currentOffsetX,(currentOffSetY - (contentHeight/2))); } } }
The code above moves the scroll position up if you have almost reached the scroll ending; Or, if you're almost on top, moves you to the bottom ...
source share