You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
3.3 KiB
87 lines
3.3 KiB
// |
|
// QDetailViewController.m |
|
// tongxin |
|
// |
|
// Created by WeiChaoZheng on 2018/11/8. |
|
// Copyright © 2018年 xTT. All rights reserved. |
|
// |
|
|
|
#import "QDetailViewController.h" |
|
|
|
@interface QDetailViewController ()<WKNavigationDelegate,WKUIDelegate> |
|
|
|
@end |
|
|
|
@implementation QDetailViewController |
|
//详细的问题页面 |
|
- (void)viewDidLoad { |
|
[super viewDidLoad]; |
|
self.title = @"常见问题"; |
|
self.titleLabel.text = self.titleStr; |
|
self.view.backgroundColor = tabViewBG; |
|
// self.contentView.layer.cornerRadius = 5; |
|
// self.contentView.layer.masksToBounds = YES; |
|
self.webView = [[WKWebView alloc] initWithFrame:CGRectZero]; |
|
[self.contentView addSubview:self.webView]; |
|
self.webView.UIDelegate = self; |
|
self.webView.navigationDelegate = self; |
|
self.webView.scrollView.bounces = NO; |
|
[self.webView mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.right.equalTo(self.view); |
|
make.top.equalTo(self.view).offset(iPhoneX_NavHeight); |
|
make.bottom.equalTo(self.view.mas_bottom); |
|
}]; |
|
self.webView.hidden = YES; |
|
|
|
if(self.content){ |
|
[self.webView loadHTMLString:[NSString stringWithFormat:@"%@%@",@"<meta name=\"viewport\" content=\"width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no\" />",self.content] baseURL:nil]; |
|
}else{ |
|
if(self.url){ |
|
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.url]]]; |
|
} |
|
|
|
} |
|
[SVProgressHUD showWithStatus:nil]; |
|
} |
|
// 页面加载完成之后调用 此方法会调用多次 |
|
- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation { |
|
[SVProgressHUD dismiss]; |
|
self.webView.hidden = NO; |
|
WEAKSELF |
|
//获取内容实际高度(像素)@"document.getElementById(\"content\").offsetHeight;" |
|
[_webView evaluateJavaScript:@"document.body.scrollHeight" completionHandler:^(id _Nullable result,NSError * _Nullable error) { |
|
// 此处js字符串采用scrollHeight而不是offsetHeight是因为后者并获取不到高度,看参考资料说是对于加载html字符串的情况下使用后者可以,但如果是和我一样直接加载原站内容使用前者更合适 |
|
//获取页面高度,并重置webview的frame |
|
double contentViewHeight = [result doubleValue]+45; |
|
// 15 是 contentView 距离顶部的 距离 ,10 是距离底部的距离 |
|
CGFloat maxHeight = ScreenHeight-getRectNavAndStatusHight - 15 - 10; |
|
|
|
if(contentViewHeight > maxHeight){ |
|
contentViewHeight = maxHeight; |
|
} |
|
if(contentViewHeight > weakSelf.contentViewHeightNSLC.constant){ |
|
dispatch_async(dispatch_get_main_queue(), ^{ |
|
weakSelf.contentViewHeightNSLC.constant = contentViewHeight; |
|
}); |
|
} |
|
|
|
}]; |
|
NSLog(@"结束加载"); |
|
|
|
} |
|
- (void)didReceiveMemoryWarning { |
|
[super didReceiveMemoryWarning]; |
|
// Dispose of any resources that can be recreated. |
|
} |
|
|
|
/* |
|
#pragma mark - Navigation |
|
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation |
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { |
|
// Get the new view controller using [segue destinationViewController]. |
|
// Pass the selected object to the new view controller. |
|
} |
|
*/ |
|
|
|
@end
|
|
|