之前做等待跳转都是用UIActivityIndicatorView ,后来做webView 加载页面的时候,发现了一个特别好用又超级炫酷的加载提示NJKWebViewProgress,作者巧妙的通过计算加载请求的个数,用百分比展示进度,并且集成了加载页面的title,效果惊艳业界。今将使用步骤记录,方便日后查询,也希望能给朋友们带来一点帮助。

1、首先将炫酷的NJKWebViewProgress 拖到工程,赶紧"占为已有"

2、在加载页面铺以下代码,由于对NJKWebViewProgress的理解都是个人的,就不一一注释了,以免不到之处误导查询者。

@interface ViewController ()<UIWebViewDelegate,NJKWebViewProgressDelegate>{

UIWebView *_webView;
    NJKWebViewProgressView *_progressView;
    NJKWebViewProgress *_progressProxy;
    NSURLRequest *req;
    
    BOOL cameraBool;
    UIImagePickerController *cameraPick;
    
    
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0,WIDTH, HEIGHT)];
    _webView.scalesPageToFit = YES;
    [self.view addSubview:_webView];
    
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(replyEvent)];
    UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshEvent)];
    
    self.navigationItem.leftBarButtonItem = item;
    self.navigationItem.rightBarButtonItem = item1;

_progressProxy = [[NJKWebViewProgress alloc] init];
    _webView.delegate = _progressProxy;
    _progressProxy.webViewProxyDelegate = self;
    _progressProxy.progressDelegate = self;
    
    CGFloat progressBarHeight = 2.f;
    CGRect navigationBarBounds = self.navigationController.navigationBar.bounds;
    CGRect barFrame = CGRectMake(0, navigationBarBounds.size.height - progressBarHeight, navigationBarBounds.size.width, progressBarHeight);
    _progressView = [[NJKWebViewProgressView alloc] initWithFrame:barFrame];
    _progressView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;

[self jump];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar addSubview:_progressView];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [_progressView removeFromSuperview];
}

-(void)replyEvent{
    
    [_webView goBack];
}

-(void)refreshEvent{
    [_webView reload];
}

-(void)jump{
    
    if(self.k == 1){
        req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://www.baidu.com/index.php?tn=monline_3_dg"]];}
//    }else if (self.k == 2){
//    req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.cnblogs.com/wangyang1213/"]];
//    }else if(self.k == 3){
//       req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.163.com/"]];
//    }
    else{
    req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://cc.yztcai.com/h5.php"]];
    }
    
    [_webView loadRequest:req];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    
    if(error != NULL){
        UIAlertController *alertController1 = [UIAlertController alertControllerWithTitle:@"提示" message:@"网络连接异常" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *sureAction1 = [UIAlertAction actionWithTitle:@"确定" style:0 handler:nil];
        UIAlertAction *cancelAction1 = [UIAlertAction actionWithTitle:@"取消" style:0 handler:nil];
        [alertController1 addAction:sureAction1];
        [alertController1 addAction:cancelAction1];
        [self presentViewController:alertController1 animated:YES completion:nil];
    }
}

-(void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(float)progress
{
    [_progressView setProgress:progress animated:YES];
    self.title = [_webView stringByEvaluatingJavaScriptFromString:@"document.title"];
}

至此便集成了NJKWebViewProgress。拖到工程试试。

最新文章

  1. 2MyBatis入门--深入浅出MyBatis技术原理与实践(笔记)
  2. AT指令调试程序
  3. 关于C语言宏定义 使用do{ xxxx }while()
  4. 各版本CRM所需端口号
  5. 在数学建模中学MATLAB
  6. Careercup - Google面试题 - 5898529851572224
  7. JodaTime用法简介
  8. Android ListView快速定位(一)
  9. 【HDOJ】4267 A Simple Problem with Integers
  10. 运用linq查找所有重复的元素
  11. The Letter Carrier&#39;s Rounds(摘)
  12. 依赖注入及AOP简述(四)——“好莱坞原则”和依赖注入框架简介 .
  13. Loadrunner之文件的上传(八)
  14. VS2015中VB.NET类(dLL)里下载并读取文件
  15. win10 uwp 读取保存WriteableBitmap 、BitmapImage
  16. 粮草先行——Android折叠屏开发技术点(二)
  17. Filebeat 日志收集器 安装和配置
  18. webpack无法热加载(__webpack_hmr 502)
  19. gitlab的fork及源项目的同步
  20. Oracle 某字段值相同的取前几条数据

热门文章

  1. ubuntu下使用codeblocks
  2. Problem E: Product
  3. C#通过WebBrowser快速扒站思路积累大量着陆页列表
  4. python自学笔记(四)python基本数据类型之元组、集合、字典
  5. [C++ Basic] Const 用法
  6. Flex LinkButton鼠标划过出现下划线
  7. Memcached源代码分析 - Memcached源代码分析之消息回应(3)
  8. Swift调用Objective C的FrameWork
  9. linux之grep用法
  10. JSON Editor 中文文档