3

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.

Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264
JWD
  • 12,188
  • 3
  • 34
  • 32

4 Answers4

5

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
}
Thanos Diacakis
  • 948
  • 9
  • 10
0

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

OrdoDei
  • 1,379
  • 2
  • 16
  • 9
0

huh?

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

Jordan
  • 21,746
  • 10
  • 51
  • 63
  • The buttons are not in the HTML, they are in the UIView that also has the UIWebView. – JWD Oct 25 '10 at 19:21
  • 1
    Ah, in that case. You can present the HTML in a separate viewController as modal view with the HTML and the buttons on the bottom. – Jordan Oct 25 '10 at 19:27
0
- (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!");
    }
    }
Alex Burov
  • 1
  • 1
  • 2