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
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!
The issue seems to be finally solved as of the first betas of Xcode 10 and iOS 12.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With