[英]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. 我想禁用
UIWebView
所有用户交互,仅应用滚动支持,因为我只想预览webView。 Is there have some good idea? 有什么好主意吗? Thanks.
谢谢。
Now I do as follows: 现在我做如下:
1.disable user interaction with my webView 1.禁用用户与我的webView的交互
2.add my scrollView ,and the frame is same as my webView 2.添加我的scrollView,框架与我的webView相同
3.in webViewDidFinishLoad
,i get content height of webView like this: 3.在
webViewDidFinishLoad
,我像这样获取webView的内容高度:
- (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: 4,当滚动我的scrollView时,设置我的webView.Scrollview的contentOffSet是这样的:
- (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. 并返回NO。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.