开发者

iPhone - UIWebView: Detect User Scrolling to Bottom of Page

开发者 https://www.devze.com 2023-01-21 03:27 出处:网络
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 s

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 adva开发者_如何学编程nce.


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
}


huh?

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


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


- (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!");
    }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消