@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