WKWebView在contentInset之外是不可点击的 [英] WKWebView isn't clickable outside it's contentInset

查看:302
本文介绍了WKWebView在contentInset之外是不可点击的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有UIWebView的应用程序,我需要将其更改为WKWebView。
一切都很完美,除非webView需要的是contentInset不是0.
问题是,WKWebView没有接收到其scrollView的contentInset边界之外的触摸。



我做了一个简单的示例应用程序来测试它:

   - (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];
}

当我滚动webView上面的顶部插页时,我无法点击该区域的webView。



我试图寻找类似的问题,但没有运气,有没有其他人遇到过这个问题?



<谢谢

解决方案

我遇到同样的问题,在iOS 8之前,我使用UIWebView,一切正常,但是WKWebview不能当内容区域显示在contentInset区域时,响应单击事件。
我终于通过在HTML字符串中添加一个空div来解决这个问题,在主体的开头。

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

然后WKWebView可以获得与set contentInset相同的效果,并正确响应用户点击!


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!

这篇关于WKWebView在contentInset之外是不可点击的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆