Friday, September 8, 2017

WKWebView isn't clickable outside it's contentInset

Leave a Comment

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 Answers

Answers 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!

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment