Skip to content

lzcuriosity/WechatWebViewProgress

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

WechatWebViewProgress

这是一个仿照微信的WebViewProgress,与github上多星的 NJKWebViewProgress 有所区别,有兴趣可以看看。

效果图

网络正常


网络不正常

使用

导入头文件

#import "LZProgresSHeader.h"

需要对象

LZWebViewProgressView *_progressView;
LZWebViewProgress *_progressProxy;

具体代码

#import "ViewController.h"
#import "LZProgresSHeader.h"

@interface ViewController ()<UIWebViewDelegate,LZWebViewProgressDelegate>

@property (weak, nonatomic) IBOutlet UIWebView *webView;

@end

@implementation ViewController
{
    LZWebViewProgressView *_progressView;
    LZWebViewProgress *_progressProxy;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
  
    self.automaticallyAdjustsScrollViewInsets = NO;

    _progressProxy = [[LZWebViewProgress 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 = [[LZWebViewProgressView alloc] initWithFrame:barFrame];
    _progressView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
    
    NSURLRequest *req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.bilibili.com"]];
    [self.webView loadRequest:req];

}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    
}

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

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

#pragma mark - NJKWebViewProgressDelegate
-(void)webViewProgress:(LZWebViewProgress *)webViewProgress updateProgress:(float)progress
{
    [_progressView setProgress:progress];
}

@end

具体可查看我的 demo 实现。

这里面的 LZWebViewProgress 文件是需要导入的SDK; WechatWebViewProgressDemo 是上面我写的使用演示demo。

详情

具体实现思路可以看看我的博客:http://lzcuriosity.github.io/2016/07/16/源码分享:仿微信的WebViewProgress/

About

仿照微信的WebView加载进度条。

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published