Ios web interaction indexing: highly available, and iosweb Indexing
Ios web interaction indexing: highly available. For how to obtain the height of WebView content, I believe many people have stepped on and cannot obtain the accuracy height, leading to page layout errors, I found a lot of information, but I cannot solve the problem. The following is my personal experience: project requirement implementation.H5 articles & Native commentsEffect: The article loads the H5 link, and the comment information is provided by the background interface, which is displayed as a list. Implementation ideas:
1. Load the H5 link of webView and set it to the headerView of tableView. The comment below is loaded and displayed with Cell.
2. In the webView callback method webViewDidFinishLoad, retrieve the webpage content height, set it to the webView height, and assign the webView to the tableView headerView again.
Tip: when assigning a View to the tableHeaderView of UITableView, you do not need to manually set the height,HeaderViewThe height of the View is automatically used.
As shown in the preceding figure, there are many similar methods. The final results are hard to obtain accurate heights, whether obtained by JS or contentSize, rather than the method:
The cause of the problem has been determined. solution:
When the webViewDidFinishLoad proxy method is called, the page may not be fully displayed, and some images may not be loaded yet. As a result, the obtained height is not the final height. After the image is loaded, the browser re-typeset, and we gave an error height before this, leading to an exception in display.
After webViewDidFinishLoad, How can I obtain the webpage content height change?
Answer:Listeners!Specific implementation process:
Add a listener to the contentSize attribute of the scrollView of webView. The contentSize will change whenever the content changes. capture this change and implement it in the monitoring method.WebViewDidFinishLoadThe code in, that is, to obtain the latest content and assign it to webView:
In addition, the solution to obtaining high accuracy using webView in cell is the same as above, but it only needs to be noted that using webView in cell involves cell reuse, which may cause webView to be loaded multiple times during sliding list, the cache height is recommended because it affects performance.
If you do not want to listen, you must first doubt yourself, do not doubt me!
1. Make sure that the webview has been added to the page and can be properly displayed. Then, continue to get the content height. If none of them are displayed, don't come to me!
2. Add a listener to the scrollview of webview. Do not add the listener to webview. Otherwise, you will not use the listener method when you are exhausted!
3. If you are using swift, learn the relevant materials first.