WKWebView isn't clickable outside it's contentInset

旧城冷巷雨未停 提交于 2020-01-20 14:25:01

问题


I have an app with a UIWebView and I need to change it into WKWebView. Everything works perfectly, except when the webView needs to be with contentInset that is not 0. The problem is, the WKWebView doesn't receive touches outside of the bounds of its scrollView's contentInset.

I've made a simple example app for testing it:

- (void)viewDidLoad {
   [super viewDidLoad];

   WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
   self.wkWebView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:config];
   [self.view addSubview:self.wkWebView];

   self.wkWebView.scrollView.contentInset = UIEdgeInsetsMake(200, 0, 0, 0);
   NSURL *url = [NSURL URLWithString:@"http:/www.google.com"];
   NSURLRequest *request = [NSURLRequest requestWithURL:url];
   [self.wkWebView loadRequest:request];
}

When I scroll the webView above it's top inset, I can't click on the webView in that area.

I've tried to look for similar issues, but had no luck, did anyone else encounter this problem?

Thanks


回答1:


I encounter the same problem, Before iOS 8, I use UIWebView, everything works fine, But WKWebview can not respond click event when content area display in contentInset area. I finally solve this problem by Add a empty div in HTML string, at the beginning the body.

<div style='width:100%;height:500px'></div>

Then the WKWebView can get the same effect like set contentInset, and respond to user tap correctly!




回答2:


The issue seems to be finally solved as of the first betas of Xcode 10 and iOS 12.



来源:https://stackoverflow.com/questions/27755251/wkwebview-isnt-clickable-outside-its-contentinset

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!