How to check if a scroll view has been scrolled to the bottom of the screen in iOS? Thanks in advance.
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
}
}
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...");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With