Search code examples
iosobjective-cios8uiscrollviewsetcontentview

How to stop a UIScrollView from scrolling when it reaches the bottom


I have the following code in place to grab the event when a UIScrollView reaches then end of its content view:

- (void) scrollViewDidEndDecelerating:(UIScrollView *) scrollView
{
    float currentEndPoint = scrollView.contentOffset.y + scrollView.frame.size.height;

    // CGPoint bottomOffset = CGPointMake(0, scrollView.contentSize.height - scrollView.bounds.size.height);
    // [scrollView setContentOffset:bottomOffset animated:NO];

    if (currentEndPoint >= scrollView.contentSize.height)
    {
        // We are at the bottom

I notice that when I scroll to the bottom it hits it and bounces back up.

If I add this:

CGPoint bottomOffset = CGPointMake(0, scrollView.contentSize.height - scrollView.bounds.size.height);
[scrollView setContentOffset:bottomOffset animated:NO];

then the scroll goes back to the bottom.

Is there any way for it to stay at the bottom without the "bounce back up" as in once it hits the bottom, stop it from moving.

Thanks.


Solution

  • You should uncheck the bounce property of scrollview. Check the screenshot!

    enter image description here