IOS UIWebView cannot determine the true height of a Web page

Source: Internet
Author: User

@interface Indeditordetailviewcontroller () <uiwebviewdelegate, njkwebviewprogressdelegate>{UIWebView *_    WebView;    Uiprogressview *_progressview; Njkwebviewprogress *_progressproxy;}    @end @implementation indeditordetailviewcontroller-(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{//general access to the page height will be obtained in this method//But the height obtained here is not necessarily the true height of the Web page,     Because the web image is not loaded, it may lead to the Web interface is not real, or long or short//You can use the following JS method to obtain, but in fact all useless/** 1, document.documentElement.offsetHeight;     2, Document.body.clientHeight;         3, Document.documentElement.scrollHeight 4, cgrect frame = webview.frame;        Cgsize fittingsize = [WebView Sizethatfits:cgsizezero]; Frame.size = fittingsize;     Webview.frame = frame; 5, Getbodyheight ()//Web page with JS to achieve a good method 6, cgfloat height = [[WebView stringbyevaluatingjavascriptfromstring:@] document.body.     ClientHeight "] floatvalue]; *///So you must find a Web load that can be fully determined 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) {[UI        Application 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; WebView completely 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

IOS UIWebView cannot determine the true height of a Web page

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.