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

查看:25
本文介绍了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天全站免登陆