[New Address of my Jane book, Welcome to click to view Oh ~] (http://www.jianshu.com/u/738a7195e913)
about the WebView content height, I believe many people have stepped on the pit, can not get to accurate height, resulting in page layout error, found a lot of information but can not solve the problem, the following is a personal experience Summary:
Project requirements to achieve H5 article & native Comment effect, the article is loaded H5 link, comment information is the backend interface provided to display in the form of a list.
realize the idea:
1. WebView load H5 link, set it for TableView Headerview, below comment information with cell loading display.
2. In the WebView callback method webviewdidfinishload get the page content height, set to webview height, and webview assigned to TableView Headerview.
TIP: When you assign a view to a UITableView Tableheaderview, you do not need to manually set the height, Headerview automatically uses the view's height.
Like the above, a lot of similar methods, whether it is JS acquisition, or Contentsize acquisition, the final results are difficult to obtain accurate height, not the method does not, but:
Webviewdidfinishload Proxy method is called, the page does not necessarily complete display, there may be pictures have not been loaded out, resulting in the height of the acquisition is small, after a while the picture is loaded, the browser will be the layout of the Web page is propped up, and we have given the height of the content of the display, Causes an exception to be displayed. the cause of the problem has been identified and resolved:
How to get to the height of Web page content after webviewdidfinishload.
Answer: Listen. Specific implementation process:
Add a listener to the Contentsize attribute of the WebView ScrollView, and whenever the content changes, the contentsize will change, capturing the change, and implementing the code in the Webviewdidfinishload in the Listener method, That is, get the latest content height assigned to WebView:
In addition, the use of webview in the cell to obtain a highly inaccurate solution is the same as above, but need to pay attention to the use of webview in the cell to the cell reuse, will cause the slide list when the webview load, affect performance, recommended cache height.
[New Address of my Jane book, Welcome to click to view Oh ~] (http://www.jianshu.com/u/738a7195e913)