Skip to content

Instantly share code, notes, and snippets.

@hoandang
Last active October 15, 2021 07:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoandang/9b807384c652a3f18e4e to your computer and use it in GitHub Desktop.
Save hoandang/9b807384c652a3f18e4e to your computer and use it in GitHub Desktop.
Detect uiscrollview position
@interface MyViewController : UIViewController<UIScrollViewDelegate>
@end

Then you can hook to the UIScrollView:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Set self as scroll view protocol
    webView.scrollView.delegate = self;
}

Then finally detect the top and bottom being reached:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{   
    if(scrollView.contentOffset.y 
       >= 
       (scrollView.contentSize.height - scrollView.frame.size.height)){
        NSLog(@"BOTTOM REACHED");
    }
    if(scrollView.contentOffset.y <= 0.0){
        NSLog(@"TOP REACHED");
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment