Commit 9fb303a4c0f9efc605d36cc94571049815c2119d
1 parent
87bc2366
提交0.0.26_更改网页加载
Showing
2 changed files
with
35 additions
and
5 deletions
CNLiveServiceCenterModule.podspec
CNLiveServiceCenterModule/Classes/CNLiveServiceCenterModule/Controller/CNLiveBCreatorViewController.m
| ... | ... | @@ -32,6 +32,15 @@ |
| 32 | 32 | @implementation CNLiveBCreatorViewController |
| 33 | 33 | |
| 34 | 34 | |
| 35 | +- (void)dealloc | |
| 36 | +{ | |
| 37 | + if (self.wkwebView && self) { | |
| 38 | + [self.wkwebView removeObserver:self forKeyPath:@"estimatedProgress"]; | |
| 39 | + } | |
| 40 | + | |
| 41 | + | |
| 42 | +} | |
| 43 | + | |
| 35 | 44 | - (void)viewDidLoad { |
| 36 | 45 | [super viewDidLoad]; |
| 37 | 46 | [self.view setBackgroundColor:[UIColor whiteColor]]; |
| ... | ... | @@ -65,6 +74,8 @@ |
| 65 | 74 | |
| 66 | 75 | self.view.backgroundColor = [UIColor whiteColor]; |
| 67 | 76 | WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, kNavigationBarHeight, kScreenWidth, KScreenHeight - kNavigationBarHeight)]; |
| 77 | + webView.navigationDelegate = self; | |
| 78 | + webView.UIDelegate = self; | |
| 68 | 79 | [self.view addSubview:webView]; |
| 69 | 80 | webView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; |
| 70 | 81 | [webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil]; |
| ... | ... | @@ -94,11 +105,16 @@ |
| 94 | 105 | if ([keyPath isEqualToString:@"estimatedProgress"]) { |
| 95 | 106 | CGFloat newProgress = [[change objectForKey:NSKeyValueChangeNewKey] doubleValue]; |
| 96 | 107 | if (newProgress == 1) { |
| 97 | - self.progressView.hidden = YES; | |
| 98 | - [self.progressView setProgress:0 animated:NO]; | |
| 108 | + if (self) { | |
| 109 | + self.progressView.hidden = YES; | |
| 110 | + [self.progressView setProgress:0 animated:NO]; | |
| 111 | + } | |
| 112 | + | |
| 99 | 113 | }else{ |
| 100 | - self.progressView.hidden = NO; | |
| 101 | - [self.progressView setProgress:newProgress animated:YES]; | |
| 114 | + if (self) { | |
| 115 | + self.progressView.hidden = NO; | |
| 116 | + [self.progressView setProgress:newProgress animated:YES]; | |
| 117 | + } | |
| 102 | 118 | } |
| 103 | 119 | } |
| 104 | 120 | } |
| ... | ... | @@ -110,6 +126,20 @@ |
| 110 | 126 | |
| 111 | 127 | } |
| 112 | 128 | |
| 129 | + // 页面开始加载时调用 | |
| 130 | +- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation { | |
| 131 | +} | |
| 132 | + // 页面加载失败时调用 | |
| 133 | +- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error { | |
| 134 | + if (self) { | |
| 135 | + [self.progressView setProgress:0.0f animated:NO]; | |
| 136 | + [QMUITips showError:@"加载失败,请检查网络" inView:self.view hideAfterDelay:0.5]; | |
| 137 | + } | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | +} | |
| 142 | + | |
| 113 | 143 | - (void)backAction:(UIBarButtonItem *)item { |
| 114 | 144 | |
| 115 | 145 | NSLog(@"输出内容"); | ... | ... |