IOS UIWebView cannot determine the actual height of the web page

Source: Internet
Author: User

IOS UIWebView cannot determine the actual height of the web page

@ Interface IndEditorDetailViewController ()
 
  
{UIWebView * _ webView; progress * _ progressView; NJKWebViewProgress * _ progressProxy;} @ end @ implementation progress-(void) viewDidLoad {_ progressView = [[UIProgressView alloc] init]; _ progressView. frame = CGRectMake (0, 0,320, 10); [self. view addSubview: _ progressView]; _ progressProxy = [[NJKWebViewProgress alloc] init]; _ webView. delegate = _ progressProxy; _ progressProxy. webViewProxyDelegate = self; _ progressProxy. progressDelegate = self;}-(void) webViewDidFinishLoad :( UIWebView *) webView {// generally, the obtained webpage height will be obtained in this method. // However, the obtained height may not be the actual height of the web page, because the web images are not fully loaded, the web interface may not be real, or the web interface may be long or short. // you may use the following js method to obtain them, but it is useless./** 110000document.doc umentElement. offsetHeight; 2. document. body. clientHeight; 32.16document.doc umentElement. scrollHeight 4, CGRect frame = webView. frame; CGSize fittingSize = [webView sizeThatFits: CGSizeZero]; frame. size = fittingSize; webView. frame = frame; 5. getBodyHeight () // Method 6. CGFloat height = [[webView stringByEvaluatingJavaScriptFromString: @ "document. body. clientHeight "] floatValue, to determine the web height // find a tool on the Internet NJKWebViewProgress} # pragma mark-NJKWebViewProgressDelegate-(void) webViewProgress :( NJKWebViewProgress *) webViewProgress updateProgress :( float) progress {if (progress = 0.0) {[UIApplication sharedApplication]. networkActivityIndicatorVisible = YES; _ progressView. progress = 0; [UIView animateWithDuration: 0.27 animations: ^ {_ progressView. alpha = 1.0 ;}] ;}if (progress = 1.0) {[UIApplication sharedApplication]. networkActivityIndicatorVisible = NO; [UIView animateWithDuration: 0.27 delay: progress-_ progressView. progress options: 0 animations: ^ {_ progressView. alpha = 0.0; // After webView is fully loaded, CGFloat height = [[_ webView stringByEvaluatingJavaScriptFromString: @ "document. body. clientHeight "] floatValue]; CGRect frame = _ webView. frame; frame. size. height = height; _ webView. frame = frame;} completion: nil];} [_ progressView setProgress: progress animated: NO];} @ end
 

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.