iOS UIWebView 無法確定web頁面的真實高度

來源:互聯網
上載者: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{ // 一般擷取網頁高度會在這個方法裡擷取 // 但這裡擷取的高度未必就是web頁面的真實高度,因為web中圖片未載入完有可能導致web介面不真實,或長或短 // 你能可能用到下面的js方法去擷取,但其實都沒用    /**     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() // 網頁用js實現好的方法     6、CGFloat height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.clientHeight"] floatValue];     */  // 所以必須要找到能完全確定web載入,才能確定web高度  // 在網上找了個工具 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;                        // webView徹底載入完            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 無法確定web頁面的真實高度

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.