简体   繁体   English

如何禁用除滚动交互外的UIWebView中的所有用户交互

[英]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.

相关问题 ios-在UIWebView中启用滚动和缩放,但禁用其他用户交互 - ios - Enable scroll and zoom in UIWebView but disable other user interaction 禁用MKMapView的所有用户交互,但给定的MKAnnotationView除外 - Disable all user interaction for MKMapView except for a given MKAnnotationView 禁用UIWebView的缩放,但保持其他用户交互 - Disable zoom in a UIWebView but keep other user interaction 目标 C:如何禁用除一个之外的所有选项卡栏的用户交互? - Objective C: How to disable user interaction to all of tab bars except one? 如何在 MKMapView 上禁用用户交互? - How to disable user interaction on MKMapView? 如何为MGLAnnotation禁用用户交互? - How to disable user interaction for MGLAnnotation? 当用户未连接到互联网时,如何禁用所有UIViewController的用户交互? - How to disable user interaction for all UIViewControllers when user is not connected to the internet? 禁用UITextField上的触摸但不是所有用户交互 - Disable touches but not all user interaction on UITextField 如何在发生交互时禁用UICollectionView中的用户交互 - how to disable user interaction in a UICollectionView while an interaction is occurring 禁用tabBar上的用户交互 - Disable user interaction on tabBar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM