How to make endless scroll view on iPhone?

I have a scrollview with 5 kinds of image 88 wide .

I want scrollview scroll to every kind of image (not paging)

and

I want to make the scrollview on the iPhone endless , which means that when it scrolls to the last element, it displays the first element next to it.

I try to perform an offset, but it stops when I move it to an offset, and I also used an apple-street scroller that prevents me from stopping every element in the center (same as the Picker view).

+6
source share
7 answers

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:

  • 1. List item

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 ...

  • 3. What is it.
+9
source

You can see one of these two options:

+8
source

It caused serious problems for a long time, so I really feel your pain. I found this control that should solve your problem: http://www.cocoacontrols.com/platforms/ios/controls/infinitescrollview

I also thought about inserting transitions and disabled scrolling to make it look like a slide show, but it should work anyway.

+4
source

Here is a brief description of the solution I used for this.

Suppose you have a counter from 0 to 9, then when you make the transition 9 → 0, you are actually fooling another 0 (name it 0) after 9 (in scrollView), make an animated transition to 0 'and make an unanimated instant transition to 0, which stands on top of scrollView.

+1
source

You can use the iCarousel library for this . https://github.com/nicklockwood/iCarousel

0
source

For anyone looking for a solution, you can also try this Infinite Scroll Picker library at https://github.com/Seitk/InfiniteScrollPicker/ This is basically drag and drop. I use it in a project and it works great.

0
source

This mini-project implements simple endless scrolling:

https://github.com/mcmatan/Infinity-tabBar-scroll-view/blob/master/README.md

0
source

Source: https://habr.com/ru/post/922352/


All Articles