如何在加载PDF后让我的UIWebView滚动

时间:2014-05-04 20:23:18

标签: ios uiwebview

所以我有一个UIWebView,它从本地文件系统加载PDF并显示它。我想让PDF在加载后向下滚动一点,而无需用户进行干预。现在,如果我将它连接到按钮并让用户按下它,我只能滚动它。

以下是我尝试的内容:

- (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];
}

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

是的,尝试在一秒半或几秒后执行操作。要执行此操作,请使用立即返回的dispatch_after,以便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];
    });
}