Coder Social home page Coder Social logo

chenxing640 / dyfprogressview Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 2.27 MB

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

License: Other

Objective-C 96.19% Ruby 3.81%
objective-c ios widget progress-bar progress progressbar progressview web-progress loading loading-animations

dyfprogressview's Introduction

如果能帮助到你,请你给一颗星,谢谢!(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:

pod 'DYFProgressView'

Or

pod 'DYFProgressView', '~> 1.2.0'

Preview

Usage

  1. 实例化
// Lazy load
- (DYFWebProgressView *)progressView {
    if (!_progressView) {
        CGFloat w = self.navigationBar.bounds.size.width;
        CGFloat h = 3.f;
        CGFloat x = 0.f;
        CGFloat y = self.navigationBar.bounds.size.height - h;

        _progressView = [[DYFWebProgressView alloc] initWithFrame:CGRectMake(x, y, w, h)];
        _progressView.lineWidth = 3.f;
        _progressView.lineColor = [UIColor colorWithRed:RGB_V(10) 
                                                  green:RGB_V(115) 
                                                   blue:RGB_V(255) 
                                                  alpha:1];
    }
    return _progressView;
}

- (UINavigationBar *)navigationBar {
    return self.navigationController.navigationBar;
}
  1. 添加到父视图
// 在开始加载进度前,调用它
- (void)loadView {
    [super loadView];
    [self addProgressView];
}

// 添加到父视图。
- (void)addProgressView {
    if (!_progressView) {
        [self.navigationBar addSubview:self.progressView];
    }
}
  1. 开始加载进度
[self.progressView startLoading];
  1. 结束加载进度
[self.progressView endLoading];

How to embed the WKWebView ?

  1. Invoked when a main frame navigation starts.
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
    // didStartProvisionalNavigation.

    NSURL *aURL = [webView.URL copy];
    NSLog(@"%s url: %@", __FUNCTION__, aURL);

    [self.progressView startLoading];
}
  1. Invoked when a server redirect is received for the main frame.
- (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation {
    // didReceiveServerRedirectForProvisionalNavigation.
    NSLog(@"%s url: %@", __FUNCTION__, webView.URL);
}
  1. Invoked when content starts arriving for the main frame.
- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation {
    NSLog(@"%s", __FUNCTION__);
}
  1. Invoked when a main frame navigation completes.
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
    NSLog(@"%s", __FUNCTION__);
    [self.progressView endLoading];
    [self setupNavigationItemTitle];
}
  1. Invoked when an error occurs while starting to load data for the main frame.
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error {
    if (!error) { return; }

    NSString *errMessage = [NSString stringWithFormat:@"%zi, %@", error.code, error.localizedDescription];
    NSLog(@"%s [error]: %@", __FUNCTION__, errMessage);

    [self.progressView endLoading];
}
  1. Invoked when an error occurs during a committed main frame navigation.
- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error {
    if (!error) { return; }

    NSString *errMessage = [NSString stringWithFormat:@"%zi, %@", error.code, error.localizedDescription];
    NSLog(@"%s [error]: %@", __FUNCTION__, errMessage);

    [self.progressView endLoading];
}
  1. Decides whether to allow or cancel a navigation.
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
    // decidePolicyForNavigationAction.
    [self setupNavigationItemTitle];

    NSURL *aURL = [navigationAction.request.URL copy];
    NSString *aUrl = aURL.absoluteString;
    NSLog(@"%s url: %@", __FUNCTION__, aUrl);

    if (![aUrl isEqualToString:@"about:blank"]) {}

    // Method NO.1: resolve the problem about '_blank'.
    //if (navigationAction.targetFrame == nil) {
        //NSLog(@"- [webView loadRequest:navigationAction.request]");
        //[webView loadRequest:navigationAction.request];
    //}

    decisionHandler(WKNavigationActionPolicyAllow);
}
  1. Creates a new web view. Resolves the problem about '_blank'.
// Method NO.2: resolve the problem about '_blank'.
- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures {
    // createWebViewWithConfiguration.

    NSURL *aURL = [navigationAction.request.URL copy];
    NSString *aUrl = aURL.absoluteString;
    NSLog(@"%s url: %@", __FUNCTION__, aUrl);

    if (!navigationAction.targetFrame.isMainFrame) {
        NSLog(@"- [webView loadRequest:navigationAction.request]");
        [webView loadRequest:navigationAction.request];
    }

    return nil;
}
  1. The navigation item’s title displayed in the navigation bar.
- (void)setupNavigationItemTitle {
    self.navigationItem.title = self.wk_webView.title;
}

Sample

dyfprogressview's People

Contributors

itenfay avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.