十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
這篇文章主要介紹了iOS中如何使用WKWebView仿微信加載進(jìn)度條,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
創(chuàng)新互聯(lián)公司專注于集安網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供集安營銷型網(wǎng)站建設(shè),集安網(wǎng)站制作、集安網(wǎng)頁設(shè)計(jì)、集安網(wǎng)站官網(wǎng)定制、小程序開發(fā)服務(wù),打造集安網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供集安網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
具體內(nèi)容如下
WKWebView添加了estimatedProgress屬性(double類型),我們可以利用該屬性來設(shè)置UIProgressView
github代碼倉庫上存放的Demo
為頁面添加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];
頁面開始加載時(shí),隱藏進(jìn)度條
//開始加載-(void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{ //開始加載的時(shí)候,讓進(jìn)度條顯示 self.progressView.hidden = NO;}
kvo 監(jiān)聽進(jìn)度
//kvo 監(jiān)聽進(jìn)度-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary
在dealloc方法里移除監(jiān)聽
-(void)dealloc{ [self.mywebView removeObserver:self forKeyPath:NSStringFromSelector(@selector(estimatedProgress))];}
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“iOS中如何使用WKWebView仿微信加載進(jìn)度條”這篇文章對大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!