简体   繁体   中英

how to disable all user interaction in UIWebView except scroll interaction

I want to disable all user interaction in my UIWebView , only apply support of scrolling, because i only want to preview the webView. Is there have some good idea? Thanks.

Now I do as follows:

1.disable user interaction with my webView

2.add my scrollView ,and the frame is same as my webView

3.in webViewDidFinishLoad ,i get content height of webView like this:

- (void)webViewDidFinishLoad:(UIWebView *)webView{
    [self defaultWebViewDidFinishLoad];
    [self.navigationItem setTitle:[self.webview stringByEvaluatingJavaScriptFromString:@"document.title"]];
    CGFloat height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue];
    self.scrollview.contentSize = CGSizeMake(DEVICE_WIDTH, height);
    self.webview.scrollView.contentSize = CGSizeMake(DEVICE_WIDTH, height);
}

4.when scroll my scrollView, set contentOffSet of my webView.Scrollview like this:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    [self.webview.scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x, scrollView.contentOffset.y)];
}

But there have a problem, many images cannot show when scrolling.

You should use this delegate function:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

And return NO.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM