Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

javascript - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...