项目作者: dgynfi

项目描述 :
超好用的进度条和网页进度条,操作简单好用。(Super useful progress bar and web page progress bar, the operation is simple and easy to use.)
高级语言: Objective-C
项目地址: git://github.com/dgynfi/DYFProgressView.git




如果能帮助到你,请你给一颗星,谢谢!(If this can help you, please give it a star. Thanks!)

DYFProgressView

超好用的进度条和网页进度条,操作简单好用。(Super useful progress bar and web page progress bar, the operation is simple and easy to use.)

License MIT
CocoaPods
CocoaPods

Group (ID:614799921)



Installation

Using CocoaPods:

  1. pod 'DYFProgressView'

Or

  1. pod 'DYFProgressView', '~> 1.2.1'

Preview



Usage

  1. 实例化
  1. // Lazy load
  2. - (DYFWebProgressView *)progressView {
  3. if (!_progressView) {
  4. CGFloat w = self.navigationBar.bounds.size.width;
  5. CGFloat h = 3.f;
  6. CGFloat x = 0.f;
  7. CGFloat y = self.navigationBar.bounds.size.height - h;
  8. _progressView = [[DYFWebProgressView alloc] initWithFrame:CGRectMake(x, y, w, h)];
  9. _progressView.lineWidth = 3.f;
  10. _progressView.lineColor = [UIColor colorWithRed:RGB_V(10)
  11. green:RGB_V(115)
  12. blue:RGB_V(255)
  13. alpha:1];
  14. }
  15. return _progressView;
  16. }
  17. - (UINavigationBar *)navigationBar {
  18. return self.navigationController.navigationBar;
  19. }
  1. 添加到父视图
  1. // 在开始加载进度前,调用它
  2. - (void)loadView {
  3. [super loadView];
  4. [self addProgressView];
  5. }
  6. // 添加到父视图。
  7. - (void)addProgressView {
  8. if (!_progressView) {
  9. [self.navigationBar addSubview:self.progressView];
  10. }
  11. }
  1. 开始加载进度
  1. [self.progressView startLoading];
  1. 结束加载进度
  1. [self.progressView endLoading];

How to embed the WKWebView ?

  1. Invoked when a main frame navigation starts.
  1. - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
  2. // didStartProvisionalNavigation.
  3. NSURL *aURL = [webView.URL copy];
  4. NSLog(@"%s url: %@", __FUNCTION__, aURL);
  5. [self.progressView startLoading];
  6. }
  1. Invoked when a server redirect is received for the main frame.
  1. - (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation {
  2. // didReceiveServerRedirectForProvisionalNavigation.
  3. NSLog(@"%s url: %@", __FUNCTION__, webView.URL);
  4. }
  1. Invoked when content starts arriving for the main frame.
  1. - (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation {
  2. NSLog(@"%s", __FUNCTION__);
  3. }
  1. Invoked when a main frame navigation completes.
  1. - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
  2. NSLog(@"%s", __FUNCTION__);
  3. [self.progressView endLoading];
  4. [self setupNavigationItemTitle];
  5. }
  1. Invoked when an error occurs while starting to load data for the main frame.
  1. - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error {
  2. if (!error) { return; }
  3. NSString *errMessage = [NSString stringWithFormat:@"%zi, %@", error.code, error.localizedDescription];
  4. NSLog(@"%s [error]: %@", __FUNCTION__, errMessage);
  5. [self.progressView endLoading];
  6. }
  1. Invoked when an error occurs during a committed main frame navigation.
  1. - (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error {
  2. if (!error) { return; }
  3. NSString *errMessage = [NSString stringWithFormat:@"%zi, %@", error.code, error.localizedDescription];
  4. NSLog(@"%s [error]: %@", __FUNCTION__, errMessage);
  5. [self.progressView endLoading];
  6. }
  1. Decides whether to allow or cancel a navigation.
  1. - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
  2. // decidePolicyForNavigationAction.
  3. [self setupNavigationItemTitle];
  4. NSURL *aURL = [navigationAction.request.URL copy];
  5. NSString *aUrl = aURL.absoluteString;
  6. NSLog(@"%s url: %@", __FUNCTION__, aUrl);
  7. if (![aUrl isEqualToString:@"about:blank"]) {}
  8. // Method NO.1: resolve the problem about '_blank'.
  9. //if (navigationAction.targetFrame == nil) {
  10. //NSLog(@"- [webView loadRequest:navigationAction.request]");
  11. //[webView loadRequest:navigationAction.request];
  12. //}
  13. decisionHandler(WKNavigationActionPolicyAllow);
  14. }
  1. Creates a new web view. Resolves the problem about ‘_blank’.
  1. // Method NO.2: resolve the problem about '_blank'.
  2. - (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures {
  3. // createWebViewWithConfiguration.
  4. NSURL *aURL = [navigationAction.request.URL copy];
  5. NSString *aUrl = aURL.absoluteString;
  6. NSLog(@"%s url: %@", __FUNCTION__, aUrl);
  7. if (!navigationAction.targetFrame.isMainFrame) {
  8. NSLog(@"- [webView loadRequest:navigationAction.request]");
  9. [webView loadRequest:navigationAction.request];
  10. }
  11. return nil;
  12. }
  1. The navigation item’s title displayed in the navigation bar.
  1. - (void)setupNavigationItemTitle {
  2. self.navigationItem.title = self.wk_webView.title;
  3. }

Sample