//
|
// PBAgreementViewController.m
|
// IphoneBIMe
|
//
|
// Created by zjf on 2018/9/5.
|
// Copyright © 2018年 ProBIM. All rights reserved.
|
//
|
|
#import "PBAgreementViewController.h"
|
#import <WebKit/WebKit.h>
|
|
@interface PBAgreementViewController ()<WKNavigationDelegate, WKUIDelegate>
|
@property (nonatomic, strong) WKWebView *wkWebView;
|
@property (nonatomic, strong) UIProgressView *progressView;
|
@end
|
|
@implementation PBAgreementViewController
|
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
[self setupNav];
|
[self setupUI];
|
}
|
- (void)setupNav {
|
self.title = @"管理平台用户协议";
|
PBBackNavItem *backNav = [PBBackNavItem backNacItem];
|
backNav.title = @"返回";
|
[backNav addTarget:self action:@selector(backNavAction) forControlEvents:UIControlEventTouchUpInside];
|
UIBarButtonItem *backNavItem = [[UIBarButtonItem alloc] initWithCustomView:backNav];
|
self.navigationItem.leftBarButtonItem = backNavItem;
|
}
|
- (void)backNavAction {
|
[self dismissViewControllerAnimated:YES completion:nil];
|
}
|
|
- (void)setupUI {
|
self.progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, 64, MainScreenWidth, 2)];
|
self.progressView.tintColor = WarningColor;
|
self.progressView.trackTintColor = [UIColor whiteColor];
|
[self.view addSubview:self.progressView];
|
|
[self.wkWebView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
|
NSString *urlString = @"http://policy.biaddti.com/policy.pdf";
|
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
|
request.timeoutInterval = 15.0f;
|
[self.wkWebView loadRequest:request];
|
}
|
|
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
|
if (object == self.wkWebView && [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.1f
|
delay:0.1f
|
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];
|
}
|
}
|
|
#pragma mark - WKWKNavigationDelegate Methods
|
//开始加载
|
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
|
self.progressView.hidden = NO;
|
[YJProgressHUD showProgress:@"" inView:self.view];
|
}
|
|
//加载完成
|
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
|
[YJProgressHUD hide];
|
}
|
|
//加载失败
|
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error {
|
[YJProgressHUD showFailed:@"加载失败" inview:self.view];
|
}
|
|
//页面跳转
|
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
|
decisionHandler(WKNavigationActionPolicyAllow);
|
}
|
|
- (WKWebView *)wkWebView {
|
if (!_wkWebView) {
|
_wkWebView = [[WKWebView alloc] initWithFrame:self.view.bounds];
|
_wkWebView.navigationDelegate = self;
|
_wkWebView.UIDelegate = self;
|
[self.view addSubview:_wkWebView];
|
}
|
return _wkWebView;
|
}
|
|
|
|
@end
|