Question

So I've got a UIWebView that loads up a PDF from local filesystem and displays it. I want to cause the PDF to scroll down a bit once it loads without the user having to intervene. Right now, I can only get it to scroll if I wire it up to a button and make the user press it.

Here's what I've tried:

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    // doesn't work
    [self.webScrollView setContentOffset:CGPointMake(0, 5000) animated:NO];
    // doesn't work
    [self buttonPressed];
}

- (IBAction)buttonPressed{
    // works
    [self.webScrollView setContentOffset:CGPointMake(0, 5000) animated:NO];
}

Any ideas?

Was it helpful?

Solution

Yes, try to perform the action after one second and half or a couple of second. To do this, use dispatch_after that return immediately so the method - (void)webViewDidFinishLoad:(UIWebView *)webView return:

- (void)webViewDidFinishLoad:(UIWebView *)webView
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)),     dispatch_get_main_queue(), ^{
        [self.webScrollView setContentOffset:CGPointMake(0, 5000) animated:NO];
    });
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top