iPhone - UIWebView:检测用户滚动到页面底部

发布于 2024-09-29 04:08:54 字数 174 浏览 5 评论 0原文

所以,我有一个 UIView,里面有一个 UIWebView,提供本地 HTML 文件(文档预览)。我也有“接受”和“ “拒绝”UIButton。我需要这些按钮仅在用户滚动到网页底部后才出现。有没有办法捕获滚动到 UIWebView 底部的事件?

我还没有看到任何好的答案,有人可以帮忙吗?

提前致谢。

So, I have a UIView with a UIWebView inside serving up a local HTML file (a document preview). I also have "Accept" & "Reject" UIButtons. I need these buttons to only appear after the user has scrolled to the bottom of the web page. Is there a way to capture an event for scrolling to the bottom of a UIWebView?

I have not seen any good answers for this, can anyone help?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

请叫√我孤独 2024-10-06 04:08:54

UIWebView 符合 UIScrollViewDelegate。因此,您可以创建 UIWebView 的子类(例如 ScrollDetectWebView)并捕获对 UIScrollViewDelegate 的调用。

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    [super scrollViewDidScroll: scrollView];

    // Whatever scroll detection you need to do
}

UIWebView conforms to UIScrollViewDelegate. As such, you can create a subclass of UIWebView (say, ScrollDetectWebView) and capture the calls to the UIScrollViewDelegate.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    [super scrollViewDidScroll: scrollView];

    // Whatever scroll detection you need to do
}
前事休说 2024-10-06 04:08:54

嗯?

为什么不将按钮放在页面底部呢?

huh?

Why not just included the buttons on the bottom of the page?

陪你搞怪i 2024-10-06 04:08:54

JavaScript 可以处理滚动事件并向 Objective-c 发送消息。

JavaScript lets handle the scrolling event and send message to Objective-c.

渡你暖光 2024-10-06 04:08:54
- (void)viewDidLoad {
    [super viewDidLoad];

     self.webView.scrollView.delegate = self;
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {

    CGSize fittingSize = [self.webView sizeThatFits:CGSizeZero];

    CGFloat height1 = scrollView.bounds.origin.y + self.webView.bounds.size.height;

    CGFloat height2 = fittingSize.height;

    int delta = fabs(height1 - height2);

    if (delta < 30) {

       NSLog(@"HELLO!!! You reached the page end!");
    }
    }
- (void)viewDidLoad {
    [super viewDidLoad];

     self.webView.scrollView.delegate = self;
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {

    CGSize fittingSize = [self.webView sizeThatFits:CGSizeZero];

    CGFloat height1 = scrollView.bounds.origin.y + self.webView.bounds.size.height;

    CGFloat height2 = fittingSize.height;

    int delta = fabs(height1 - height2);

    if (delta < 30) {

       NSLog(@"HELLO!!! You reached the page end!");
    }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文