Search code examples
cocoa-touchuiscrollviewscrollpositionuiscrollviewdelegate

UIScrollView issue


I'm building an application that uses an UIScrollView. I need to detect when the user reaches the end of the content. It works fine when talking about the left side. Here's my code:

    if([scrollView contentOffset].x < -120.0f)
    [self prev:nil];

I wish I could say the same about the right side. A NSLog releaved me the problem

    NSLog(@"Off %f, content %f", [scrollView contentOffset].x, [scrollView contentSize].width);

When I scroll to the limit of the content, I see this:

2011-03-16 14:24:40.920 Digibi[1774:707] Off 627.000000, content 1106.286011

Does anyone knows a good solution for that?

Thanks in advanced.


Solution

  • The content offset is measured from the left edge of the scroll view's content. In this case, the difference between the content width and the content offset is approximately 480 pixels—presumably the width of your scroll view. Just add the width of the scroll view's bounds to the content offset when you need to check where the right edge is.