在UIWebView滚动时调用方法 [英] Calling a method when UIWebView scrolls

查看:148
本文介绍了在UIWebView滚动时调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含大量文本内容的UIWebView。我需要能够在每次移动时获取UIWebView的位置。我正在使用此代码来说明问题:

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];

现在我只需要这样做,以便每次UIWebView位置移动时更新此变量值,或者有任何滚动。是否可以在UIWebView滚动时调用方法?

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?

推荐答案

您应该扩展UIWebView,如下所示

You should extend UIWebView, like below

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

并在你的控制器上实现scrollViewDidScroll,如:

and implement scrollViewDidScroll on your controller like:

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

并且不要忘记将控制器设置为UIWebView的委托属性。

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

这篇关于在UIWebView滚动时调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆