Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make infinite scroll view in iPhone?

I have a scrollview with 5 image views of width 88.

I want the scrollview to scroll to each image view (Not Paging)

and

I want to make an infinite scrollview in iPhone which means the when it scroll to last item it will display a first item next to it..

I have been trying by offset but it stops when move it by offset and also I have used apple street scroller which does not allow me to stop each element in center(just like Picker view)..

like image 445
Asadullah Ali Avatar asked Aug 08 '12 10:08

Asadullah Ali


People also ask

How do I turn endless scroll on?

Disabling Infinite Scroll However, you can turn it on or off any time by toggling the “Infinite Scroll” option on My Site → Settings → Writing. Additionally, adding a footer widget will also disable the Infinite Scroll option.

What is infinite scroll enabled?

Infinite scrolling is a listing-page design approach which loads content continuously as the user scrolls down. It eliminates the need for pagination — breaking content up into multiple pages.

What is scroll view in IOS?

Scroll View is used for displaying content more than the size of the screen. It can contain all of the other UI elements like image views, labels, text views and even another scroll view itself.

Is infinite scroll good?

Infinite scroll is great for touchscreens and especially for mobile devices. A user can easily swipe down to keep generating new content instead of switching to new tabs, which can feel cumbersome.


1 Answers

First of all, I recommend to use a UITableView so you can maintain the memory usage low. An approach that I had used successfully in a project is the following:

    1. List item

Duplicate the content of your cells, I mean if you have 5 items in this way:

| 1 | 2 | 3 | 4 | 5 |

You should add the same (In a table view with reusable engine that's not a big deal) at the end of the table in order to look like this:

| 1 | 2 | 3 | 4 | 5 | 1 | 2 | 3 | 4 | 5 |

    2. modify the scrollViewDidScroll with the following:
-(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 move the scroll position at top if you almost reach the final of the scrolling; Or if you are almost on the top, moves you to the bottom...

    3. That's it.
like image 74
D33pN16h7 Avatar answered Oct 11 '22 20:10

D33pN16h7