Commit 6b473c0d122bea4b0e81f4f7c31f73559be595cd

Authored by 梁星国
1 parent a5ffeb79

提交添加web进度条

CNLiveServiceCenterModule.podspec
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 8
9 Pod::Spec.new do |s| 9 Pod::Spec.new do |s|
10 s.name = 'CNLiveServiceCenterModule' 10 s.name = 'CNLiveServiceCenterModule'
11 - s.version = '0.0.11' 11 + s.version = '0.0.12'
12 s.summary = '网家家企业端服务中心模块' 12 s.summary = '网家家企业端服务中心模块'
13 13
14 # This description is used to generate tags and improve search results. 14 # This description is used to generate tags and improve search results.
CNLiveServiceCenterModule/Classes/CNLiveServiceCenterModule/Controller/CNLiveBCreatorViewController.m
@@ -30,6 +30,9 @@ @@ -30,6 +30,9 @@
30 30
31 @property (strong, nonatomic) NSString *url; 31 @property (strong, nonatomic) NSString *url;
32 32
  33 +@property (assign,nonatomic) NSUInteger loadCount;
  34 +@property (assign,nonatomic) UIProgressView *progressView;
  35 +
33 @end 36 @end
34 37
35 @implementation CNLiveBCreatorViewController 38 @implementation CNLiveBCreatorViewController
@@ -46,14 +49,46 @@ @@ -46,14 +49,46 @@
46 49
47 -(void)initWKWebView 50 -(void)initWKWebView
48 { 51 {
  52 +
  53 + UIProgressView *progress = [[UIProgressView alloc]initWithFrame:CGRectMake(0, kNavigationBarHeight, KScreenWidth, 1)];
  54 + progress.tintColor = RGBOF(0x389FEF);
  55 + progress.trackTintColor = [UIColor whiteColor];
  56 + [self.view addSubview:progress];
  57 + self.progressView = progress;
  58 +
  59 +
49 self.view.backgroundColor = [UIColor whiteColor]; 60 self.view.backgroundColor = [UIColor whiteColor];
50 self.url = CNLiveBCenterCreaterUrl; 61 self.url = CNLiveBCenterCreaterUrl;
51 WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, KScreenHeight)]; 62 WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, KScreenHeight)];
52 - self.view = webView; 63 + [self.view addSubview:webView];
  64 + webView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
  65 + [webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
53 NSURL *url = [NSURL URLWithString:self.url]; 66 NSURL *url = [NSURL URLWithString:self.url];
54 NSURLRequest *request = [NSURLRequest requestWithURL:url]; 67 NSURLRequest *request = [NSURLRequest requestWithURL:url];
55 [webView loadRequest:request]; 68 [webView loadRequest:request];
  69 +
  70 + [self.view insertSubview:webView belowSubview:progress];
  71 +
  72 +}
56 73
  74 +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
  75 +
  76 + if ([keyPath isEqualToString:@"estimatedProgress"]) {
  77 + CGFloat newProgress = [[change objectForKey:NSKeyValueChangeNewKey] doubleValue];
  78 + if (newProgress == 1) {
  79 + self.progressView.hidden = YES;
  80 + [self.progressView setProgress:0 animated:NO];
  81 + }else{
  82 + self.progressView.hidden = NO;
  83 + [self.progressView setProgress:newProgress animated:YES];
  84 + }
  85 + }
  86 +}
  87 +
  88 +- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{
  89 + // 在发送请求之前,决定是否跳转
  90 + decisionHandler(WKNavigationActionPolicyAllow);
  91 +
57 92
58 } 93 }
59 94