Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WKWebView not rendering correctly in iOS 10

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.

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.

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

Open Radar: https://openradar.appspot.com/radar?id=4944718286815232

Update: This issue is resolved in iOS11

like image 574
wint Avatar asked Sep 17 '16 16:09

wint


People also ask

What is use of UIWebView or WKWebView?

A WKWebView object is a platform-native view that you use to incorporate web content seamlessly into your app's UI. A web view supports a full web-browsing experience, and presents HTML, CSS, and JavaScript content alongside your app's native views.

How can I clear the contents of a UIWebView WKWebView?

To clear old contents of webview With UIWebView you would use UIWebViewDelegate 's - webViewDidFinishLoad: .

How do I import WKWebView into Objective C?

You can implement WKWebView in Objective-C, here is simple example to initiate a WKWebView : WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init]; WKWebView *webView = [[WKWebView alloc] initWithFrame:self. view. frame configuration:theConfiguration]; webView.


1 Answers

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()         }     } } 
like image 189
ETHAN Avatar answered Oct 01 '22 01:10

ETHAN