iOS UIWebView 之 UIProgressView
之前做等待跳转都是用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。拖到工程试试。
iOS UIWebView 之 UIProgressView的更多相关文章
- ios UIWebView截获html并修改便签内容(转载)
ios UIWebView截获html并修改便签内容 博客分类: iphone开发iphone开发phoneGap uiwebviewstringByEvaluatingJavaScriptFromS ...
- IOS UIWebView截获html并修改便签内容,宽度自适应
需求:混合应用UIWebView打开html后,UIWebView有左右滚动条,要去掉左右滚动效果: 方法:通过js截获UIWebView中的html,然后修改html标签内容: 实例代码: 服 ...
- ios UIWebView截获html并修改便签内容
需求:混合应用UIWebView打开html后,UIWebView有左右滚动条,要去掉左右滚动效果: 方法:通过js截获UIWebView中的html,然后修改html标签内容: 实例代码: 服务器端 ...
- iOS UIWebView 获取内容实际高度,关闭滚动效果
本文转载至 http://my.oschina.net/Khiyuan/blog/341535 iOS UIWebView 获取内容实际高度,关闭滚动效果 近期做东西,将 UIWebView 嵌套 ...
- iOS UIWebView获取403/404
问题描述 与WindowsPhone不同,iOS UIWebView并不认为403/404这种情况下页面访问是失败的,这也情有可原,但有时候,我们需要对WebView所遇到的403/404进行处理. ...
- iOS UIWebView与JavaScript的交互 相关资料
UIWebView自适应宽度 iOS UIWebView中javascript与Objective-C交互.获取摄像头 iOS中JavaScript和OC交互 iOS与js交互,获取webview完整 ...
- ios UIWebView自定义Alert风格的弹框
之前开发过一个App,因为公司之前写好了网页版的内容和安卓版本的App,我进去后老板要求我ios直接用网页的内容,而不需要自己再搭建框架.我一听,偷笑了,这不就是一个UIWebView吗?简单! 但是 ...
- iOS --- UIWebView的加载本地数据的三种方式
UIWebView是IOS内置的浏览器,可以浏览网页,打开文档 html/htm pdf docx txt等格式的文件. safari浏览器就是通过UIWebView做的. 服务器将MIM ...
- iOS UIWebView中javascript与Objective-C交互、获取摄像头
UIWebView是iOS开发中常用的一个视图控件,多数情况下,它被用来显示HTML格式的内容. 支持的文档格式 除了HTML以外,UIWebView还支持iWork, Office等文档格式: Ex ...
随机推荐
- C/C++修改常量的值
C/C++中常量修饰const可以用来保证一些确定的量不会被一不小心改变,比如PI,一直是3.14159...... 但是不排除有时候也会需要修改常量的值,通过直接修改是不能达到目的. 比如: #in ...
- 转移服务器,DEDE网站遇到no input file specified!
公司新配置了服务器,需要从旧服务器上把原来的站点迁移到新服务器,迁移.NET网站没有遇到任何问题,但是在迁移过来一个用DEDE做的网站后,访问首页出现No Input File Specified,后 ...
- hihocoder #1260 : String Problem I
题目链接 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 我们有一个字符串集合S,其中有N个两两不同的字符串. 还有M个询问,每个询问给出一个字符串w,求有多少S中的 ...
- 整理网站优化(SEO)的方案
首先,我们来确定一下seo方案的定义是什么,所谓seo方案是指针对于某个网站,在完成了解熟悉的情况下,结合自身的一套seo优化方法来制定完成符合这个网站seo推广思路和策略.接下来就了解一下新手seo ...
- Linux串口编程详解(转)
串口本身,标准和硬件 † 串口是计算机上的串行通讯的物理接口.计算机历史上,串口曾经被广泛用于连接计算机和终端设备和各种外部设备.虽然以太网接口和USB接口也是以一个串行流进行数据传送的,但是串口连接 ...
- S70卡
产品名称:Mifare 4K(S70)卡 芯片类型:Philips Mifare 1 S70(MOA2) 存储容量:32Kbit,32个分区,每分区两组密码 工作频率:13.56 MHz 通讯 ...
- Oracle 动态查询,EXECUTE IMMEDIATE select into使用方法
create or replace procedure TEST_TABLE is l_table_name varchar2(50); query_stat varchar2(100); l_zyq ...
- android程序报错“error launching activity com.android.ddmlib.shellcommandunresponsiveexception”的解决方式
今天在调试android程序的时候,因为是NDK开发,要先编译.so库再打包下载到android模拟器,所以花费的时间比較长.控制台就会报例如以下错误: error launching activit ...
- 初学MVC
学习MVC基础:C#. ADO.NET .html.javascript.ASP.Net .WebFrom MVC模式两种理解:一种是表现模式,另一种是架构模式.它将应用程序分成三个主要的组件:视图( ...
- dict和set的使用
使用dict和set dict Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度. 举个例子 ...