Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a method when UIWebView scrolls

I have a UIWebView that contains a lot of text content. I need to be able to get the location of the UIWebView every time it moves. I am using this code to get the point:

pageYOffset = [[webView stringByEvaluatingJavaScriptFromString:@"window.pageYOffset"] intValue];

now I just need to make it so that this variables value is updated everytime the UIWebView position moves, or there is any scrolling. Is it possible to call a method whenever the UIWebView scrolls?

like image 234
Jerry Avatar asked Jul 19 '26 16:07

Jerry


2 Answers

You should extend UIWebView, like below

@implementation UIWebView(CustomScroll)
- (void) scrollViewDidScroll:(UIScrollView *)scrollView{
    [self.delegate scrollViewDidScroll: scrollView];
}
@end

and implement scrollViewDidScroll on your controller like:

- (void) scrollViewDidScroll:(UIScrollView *)scrollView{
    NSLog("webview scrolled");
}

and don't forget to set your controller to the delegate property of UIWebView.

like image 185
Deniz Mert Edincik Avatar answered Jul 22 '26 05:07

Deniz Mert Edincik


I believe that if your header lists your VC as a UIScrollViewDelegate, you can use the -(void)scrollViewDidScroll:(UIScrollView *)scrollView method to find out when it scrolls.

like image 30
Kolin Krewinkel Avatar answered Jul 22 '26 06:07

Kolin Krewinkel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!