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.
100 lines
3.9 KiB
100 lines
3.9 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.view.backgroundColor = KKWhiteColorColor; |
|
|
|
UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:FontBold_(18) textColor:KKBlack20 text:self.titleStr Radius:0]; |
|
[self.view addSubview:titleLabel]; |
|
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.right.equalTo(self.view).inset(16); |
|
make.top.equalTo(self.view).offset(iPhoneX_NavHeight+15); |
|
}]; |
|
|
|
UILabel *line = [UILabel new]; |
|
line.backgroundColor = RGB(240, 240, 240); |
|
[self.view addSubview:line]; |
|
[line mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.right.equalTo(self.view).inset(16); |
|
make.top.equalTo(titleLabel.mas_bottom).offset(10); |
|
make.height.mas_equalTo(0.5); |
|
}]; |
|
|
|
self.webView = [[WKWebView alloc] initWithFrame:CGRectZero]; |
|
[self.view 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).inset(5); |
|
make.top.equalTo(line.mas_bottom).offset(5); |
|
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]]]; |
|
} |
|
|
|
} |
|
} |
|
// 页面加载完成之后调用 此方法会调用多次 |
|
- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation { |
|
[UICommon HidenLoading]; |
|
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
|
|
|