|
@@ -0,0 +1,164 @@
|
|
|
+//
|
|
|
+// JYNewWebController.m
|
|
|
+// JianYuIOS
|
|
|
+//
|
|
|
+// Created by apple on 2020/6/11.
|
|
|
+// Copyright © 2020 lixianglan. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+#import "JYNewWebController.h"
|
|
|
+#import <WebKit/WebKit.h>
|
|
|
+
|
|
|
+@interface JYNewWebController ()
|
|
|
+
|
|
|
+
|
|
|
+@property (nonatomic, strong) UIProgressView *progressView;
|
|
|
+@property (nonatomic, strong) WKWebView *webView;
|
|
|
+
|
|
|
+@end
|
|
|
+
|
|
|
+@implementation JYNewWebController
|
|
|
+
|
|
|
+-(void)viewWillAppear:(BOOL)animated
|
|
|
+{
|
|
|
+ [super viewWillAppear:animated];
|
|
|
+ [self.navigationController setNavigationBarHidden:YES animated:animated];
|
|
|
+}
|
|
|
+//进度条
|
|
|
+- (UIProgressView *)progressView
|
|
|
+{
|
|
|
+ if (_progressView == nil) {
|
|
|
+ _progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0,STATUS_BAR_HEIGHT - 2,WIDTH,2)];
|
|
|
+ _progressView.tintColor = [UIColor blueColor];
|
|
|
+ _progressView.trackTintColor = [UIColor whiteColor];
|
|
|
+ }
|
|
|
+ return _progressView;
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - event response
|
|
|
+// 计算wkWebView进度条
|
|
|
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
|
|
|
+ if (object == self.webView && [keyPath isEqualToString:@"estimatedProgress"]) {
|
|
|
+ CGFloat newprogress = [[change objectForKey:NSKeyValueChangeNewKey] doubleValue];
|
|
|
+ self.progressView.alpha = 1.0f;
|
|
|
+ [self.progressView setProgress:newprogress animated:YES];
|
|
|
+ if (newprogress >= 1.0f) {
|
|
|
+ [UIView animateWithDuration:0.3f
|
|
|
+ delay:0.3f
|
|
|
+ options:UIViewAnimationOptionCurveEaseOut
|
|
|
+ animations:^{
|
|
|
+ self.progressView.alpha = 0.0f;
|
|
|
+ }
|
|
|
+ completion:^(BOOL finished) {
|
|
|
+ [self.progressView setProgress:0 animated:NO];
|
|
|
+ }];
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+-(void)initUI {
|
|
|
+ //默认都隐藏
|
|
|
+ UIButton *backBtn_1 = [ZKControl createButtonWithFrame:CGRectMake(15, STATUS_BAR_HEIGHT+15, 30, 30) title:@"" imageName:@"back_normal" bgImageName:nil target:self method:@selector(backBtn1Click)];
|
|
|
+ backBtn_1.backgroundColor = [UIColor blackColor];
|
|
|
+ backBtn_1.layer.cornerRadius = 15;
|
|
|
+ backBtn_1.layer.masksToBounds = YES;
|
|
|
+
|
|
|
+
|
|
|
+ UIView *titleView = [ZKControl createViewWithFrame:CGRectMake(0, 0, WIDTH, NAVIGATION_BAR_HEIGHT) color:[UIColor whiteColor]];
|
|
|
+ [self.view addSubview:titleView];
|
|
|
+
|
|
|
+
|
|
|
+ //默认都隐藏
|
|
|
+ UIButton *backBtn_2 = [ZKControl createButtonWithFrame:CGRectMake(10, STATUS_BAR_HEIGHT, 60, 44) title:@"" imageName:@"arrowLeft" bgImageName:nil target:self method:@selector(backBtn2Click)];
|
|
|
+ UILabel *titleLabel = [ZKControl createLabelWithFrame:CGRectMake(50, STATUS_BAR_HEIGHT, WIDTH-100, 44) font:17 text:@"公告信息" TextAlignment:NSTextAlignmentCenter TextColor:UIColorFromRGB(0x333333) bgColor:nil];
|
|
|
+ UIView *lineView= [ZKControl createViewWithFrame:CGRectMake(0, NAVIGATION_BAR_HEIGHT-1, WIDTH, 1) color:[UIColor groupTableViewBackgroundColor]];
|
|
|
+
|
|
|
+ [titleView addSubview:titleLabel];
|
|
|
+ [titleView addSubview:backBtn_2];
|
|
|
+ [titleView addSubview:lineView];
|
|
|
+ CGFloat H = 0.0;
|
|
|
+ if (self.titleShow) {
|
|
|
+ if ([self.titleShow isEqualToString:@"-1"]) {
|
|
|
+ titleView.hidden = YES;
|
|
|
+ backBtn_1.hidden = YES;
|
|
|
+ }else {
|
|
|
+ titleView.hidden = NO;
|
|
|
+ backBtn_1.hidden = YES;
|
|
|
+ H = NAVIGATION_BAR_HEIGHT;
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ titleView.hidden = YES;
|
|
|
+ backBtn_1.hidden = NO;
|
|
|
+ }
|
|
|
+
|
|
|
+ self.webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, H, WIDTH, HEIGHT-TAB_BAR_HEIGHT)];
|
|
|
+ if (iPhoneX) {
|
|
|
+ if (@available(iOS 11.0, *)) {
|
|
|
+ self.webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.webView.scrollView.bounces = NO;
|
|
|
+ [self.webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
|
|
|
+ [self.view addSubview:self.webView];
|
|
|
+ [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.url]]];
|
|
|
+ [self.view addSubview:backBtn_1];
|
|
|
+ [self.view addSubview:titleView];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)viewDidLoad {
|
|
|
+ [super viewDidLoad];
|
|
|
+ // Do any additional setup after loading the view.
|
|
|
+
|
|
|
+ self.view.backgroundColor = [UIColor whiteColor];
|
|
|
+ NSLog(@"title:%@",self.title);
|
|
|
+ [self initUI];//渲染页面
|
|
|
+ [self.view addSubview:self.progressView];
|
|
|
+
|
|
|
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissSelf) name:@"kNewWebControllerDismiss" object:nil];
|
|
|
+}
|
|
|
+
|
|
|
+-(void)backBtn1Click
|
|
|
+{
|
|
|
+ if (self.webView.canGoBack) {// web能退 就后退
|
|
|
+ [self.webView goBack];
|
|
|
+ }else{// 跳回上级页面
|
|
|
+ [self dismissViewControllerAnimated:NO completion:nil];
|
|
|
+ }
|
|
|
+}
|
|
|
+-(void)backBtn2Click
|
|
|
+{
|
|
|
+ if (self.webView.canGoBack) {// web能退 就后退
|
|
|
+ [self.webView goBack];
|
|
|
+ }else{// 跳回上级页面
|
|
|
+ [self dismissViewControllerAnimated:NO completion:nil];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+-(void)dismissSelf{
|
|
|
+ kMainQueue(^{
|
|
|
+ [self dismissViewControllerAnimated:NO completion:nil];
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+#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
|