WKWebView无法在iOS 10中正确呈现 [英] WKWebView not rendering correctly in iOS 10

查看:103
本文介绍了WKWebView无法在iOS 10中正确呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UITableViewCell中有WKWebView.Web视图加载请求,然后在完成加载后,我将Web视图的高度调整为等于其内容高度,然后调整表格视图单元格的高度以适合其大小.

I have WKWebView inside the UITableViewCell. The web view load request and then after finished loading, I'll resize the web view height to be equal to its content height, then adjust table view cell height to fit accordingly.

发生的事情是Web视图仅显示适合屏幕尺寸的区域.当我向下滚动时,一切都是白色的.但是我看到以正确的高度呈现的Web视图,点击并按住Web视图的白色区域仍会看到选择.捏一下即可放大显示在屏幕上的网络视图区域,但其他区域有时会变成白色.

What happened was the web view only displays the area that fit the screen size. When I scroll down, everything is white. But I see that the web view rendered with correct height, tap and hold on the white area on the web view still see selection. Zooming with pinch makes the web view area that displaying on the screen visible, but other areas sometimes become white.

在iOS 8和9上运行良好.我创建了一个示例项目来在此处演示此行为: https://github.com/pawin/strange-wkwebview

It works fine on iOS 8 and 9. I have created a sample project to demonstrate this behaviour here: https://github.com/pawin/strange-wkwebview

打开雷达: https://openradar.appspot.com/radar?id=4944718286815232

推荐答案

在滚动 UITableView 时,您需要强制 WKWebView 进行布局.

You need to force the WKWebView to layout while your UITableView scrolls.

// in the UITableViewDelegate
func scrollViewDidScroll(scrollView: UIScrollView) {
    if let tableView = scrollView as? UITableView {
        for cell in tableView.visibleCells {
            guard let cell = cell as? MyCustomCellClass else { continue }
            cell.webView?.setNeedsLayout()
        }
    }
}

这篇关于WKWebView无法在iOS 10中正确呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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