十年網(wǎng)站開(kāi)發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營(yíng)維護(hù)+專業(yè)推廣+無(wú)憂售后,網(wǎng)站問(wèn)題一站解決
今天就跟大家聊聊有關(guān)iOS中怎么利用WKWebView實(shí)現(xiàn)微信加載進(jìn)度條,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設(shè),北塔企業(yè)網(wǎng)站建設(shè),北塔品牌網(wǎng)站建設(shè),網(wǎng)站定制,北塔網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,北塔網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
為頁(yè)面添加UIProgressView屬性
@property (nonatomic, strong) WKWebView *mywebView; @property (nonatomic, strong) UIProgressView *progressView;//設(shè)置加載進(jìn)度條
懶加載UIProgressView
-(UIProgressView *)progressView{ if (!_progressView) { _progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault]; _progressView.frame = CGRectMake(0, 64, screen_width, 5); [_progressView setTrackTintColor:[UIColor colorWithRed:240.0/255 green:240.0/255 blue:240.0/255 alpha:1.0]]; _progressView.progressTintColor = [UIColor greenColor]; } return _progressView; }
在初始化WKWebView時(shí)(我是在懶加載時(shí)) kvo 添加監(jiān)控
[_mywebView addObserver:self forKeyPath:NSStringFromSelector(@selector(estimatedProgress)) options:0 context:nil];
頁(yè)面開(kāi)始加載時(shí),隱藏進(jìn)度條
//開(kāi)始加載 -(void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{ //開(kāi)始加載的時(shí)候,讓進(jìn)度條顯示 self.progressView.hidden = NO; }
kvo 監(jiān)聽(tīng)進(jìn)度
//kvo 監(jiān)聽(tīng)進(jìn)度 -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void *)context{ if ([keyPath isEqualToString:NSStringFromSelector(@selector(estimatedProgress))] && object == self.mywebView) { [self.progressView setAlpha:1.0f]; BOOL animated = self.mywebView.estimatedProgress > self.progressView.progress; [self.progressView setProgress:self.mywebView.estimatedProgress animated:animated]; if (self.mywebView.estimatedProgress >= 1.0f) { [UIView animateWithDuration:0.3f delay:0.3f options:UIViewAnimationOptionCurveEaseOut animations:^{ [self.progressView setAlpha:0.0f]; } completion:^(BOOL finished) { [self.progressView setProgress:0.0f animated:NO]; }]; } }else{ [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; } }
在dealloc方法里移除監(jiān)聽(tīng)
-(void)dealloc{ [self.mywebView removeObserver:self forKeyPath:NSStringFromSelector(@selector(estimatedProgress))]; }
看完上述內(nèi)容,你們對(duì)iOS中怎么利用WKWebView實(shí)現(xiàn)微信加載進(jìn)度條有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。