Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WKWebView isn't clickable outside it's contentInset

Tags:

ios8

wkwebview

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

like image 996
oren Avatar asked Jan 03 '15 13:01

oren


2 Answers

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!

like image 137
smileEvday Avatar answered Dec 07 '22 13:12

smileEvday


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

like image 34
underkuerbis Avatar answered Dec 07 '22 13:12

underkuerbis