3

How to check if a scroll view has been scrolled to the bottom of the screen in iOS? Thanks in advance.

anirudh
  • 4,116
  • 2
  • 20
  • 35
Rafay
  • 99
  • 2
  • 10

2 Answers2

5

implement UIScrollViewDelegate in the class that hosts UIScrollView.

set the scrollView.delegate property.

implement below method.

-(void)scrollViewDidScroll: (UIScrollView*)scrollView
{
    float scrollViewHeight = scrollView.frame.size.height;
    float scrollContentSizeHeight = scrollView.contentSize.height;
    float scrollOffset = scrollView.contentOffset.y;

    if (scrollOffset + scrollViewHeight == scrollContentSizeHeight)
    {
        //This condition will be true when scrollview will reach to bottom
    }

}
2intor
  • 1,044
  • 1
  • 8
  • 19
2

Implement the scrollview delegate and write below code into it.

- (void)scrollViewDidScroll:(UIScrollView *)aScrollView {
    CGPoint offset = aScrollView.contentOffset;
    CGRect bounds = aScrollView.bounds;
    CGSize size = aScrollView.contentSize;
    UIEdgeInsets inset = aScrollView.contentInset;
    float y = offset.y + bounds.size.height - inset.bottom;
    float h = size.height;

    if(y >= h) {
        NSLog(@"At the bottom...");
    }
}
Apurv
  • 17,116
  • 8
  • 51
  • 67