views:

340

answers:

3

I have a UIScrollView that contains large images and am using paging to scroll between images. In order to save memory, I am loading only one image before and after the currently visible one and loading/releasing new images after a scroll has completed.

The problem occurs when one scrolls quickly and scrollViewDidEndDecelerating is not called.

How can I detect continuous scrolling?

I could check item location on every scrollViewDidScroll but this seems a bit heavy...

A: 

My temporary solution is to cancel continuous scrolling by disabling scroll from when the user lifts the finger until scroll has completed.

-(void) scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
    [scrollView setScrollEnabled:NO];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    [scrollView setScrollEnabled:YES];
}
jean
A: 

You can do something like this

-(void)scrollViewDidScroll:(UIScrollView *)scrollView {

CGFloat pageWidth = scrollView.frame.size.width; int page = floor((scrollView.contentOffset.x - pageWidth / 1.5) / pageWidth) + 1;

}

this method is called anytime the contentoffset changed whether programmatically or not.

From this method you can check to see if 'page' is the same as your current page, if not, you know you need to load something. The trick here is making images load without holding up the scrolling of the scrollview. That is where I am stuck.

the page calculation will change to next/previous when you are half way to the next page

maxpower
A: 

if you are still looking for a solution... this what I do, it works really good having a good performance, too.

- (void)scrollViewDidEndDragging:(UIScrollView *)sv willDecelerate:(BOOL)decelerate
{
    if (!decelerate)
    {
        // load images and unload the ones that are not needed anymore
        [self someMethod]
    }
}


- (void)scrollViewDidEndDecelerating:(UIScrollView *)sv
{
    // load images and unload the ones that are not needed anymore
    [self someMethod]
}
jd291