IOS "Wild path" accurate access to webview content height, adaptive height

Source: Internet
Author: User
[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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.