MBProgressHUD基础用法
MBProgressHUD版本号:0.9.2
以前用MBProgressHUD用得挺好的,基本上
- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block completionBlock:(void (^)())completion ;
这套方法上去就没事了,但是现在不行了,老是提示要用GCD
'showAnimated:whileExecutingBlock:completionBlock:' is deprecated: Use GCD directly.
没办法,只能去网上下载了:https://github.com/jdg/MBProgressHUD
看了一下Demo,还真改了,上代码吧。
#import "ViewController.h"
#import "MBProgressHUD.h" #define iOS7 [[[UIDevice currentDevice] systemVersion] floatValue]>=7.0
@interface ViewController ()<MBProgressHUDDelegate> @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
[self createView]; //创建各种HUD效果的点击按钮
} //创建各种HUD效果的点击按钮
- (void)createView{ NSArray *HudTypeArray =[NSArray arrayWithObjects:@"菊花怪",@"圆饼图",@"进度条",@"圆环",@"文字",@"自定义",nil];
for (int i=0; i<HudTypeArray.count; i++) {
UIButton *hudButton =[UIButton buttonWithType:UIButtonTypeCustom];
hudButton.frame = CGRectMake(50, (50+20)*i+44+20, 100, 50);
[hudButton setTitle:HudTypeArray[i] forState:UIControlStateNormal];
[hudButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
hudButton.backgroundColor =[UIColor orangeColor];
hudButton.tag = 1000+i;
[hudButton addTarget:self action:@selector(hudAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:hudButton];
}
} //设置hud的提示文字、样式、代理等等
- (void)hudAction:(UIButton *)button { MBProgressHUD *HUD =[MBProgressHUD showHUDAddedTo:self.view animated:YES]; //HUD效果添加哪个视图上
HUD.label.text = @"正在努力加载中..."; //加载时的提示文字
HUD.detailsLabel.text = @"猪猪侠在这"; //详细提示文字,跟UITableViewCell的detailTextLabel差不多
HUD.delegate = self; //我在这里设置,只为实现hudWasHidden方法,使hud消失时能清理对象,省出内存
switch (button.tag-1000) {
case 0:
//菊花怪
HUD.mode =MBProgressHUDModeIndeterminate; //加载效果的显示样式 break;
case 1:
//圆饼图
HUD.mode = MBProgressHUDModeDeterminate;
break;
case 2:
//进度条
HUD.mode =MBProgressHUDModeDeterminateHorizontalBar; break;
case 3:
//圆环
HUD.mode =MBProgressHUDModeAnnularDeterminate; break;
case 4:
//文字
HUD.mode =MBProgressHUDModeText; break;
case 5:
//自定义
HUD.mode =MBProgressHUDModeCustomView; break; default:
break;
} if (button.tag-1000==5) {
[self custonView:HUD]; //自定义HUD效果
}else{
[self animationHud:HUD]; ////MBProgressHUD自带HUD效果
} } //MBProgressHUD自带视图
- (void)animationHud:(MBProgressHUD *)hud {
/**
MBProgressHUD 0.92与先前某些版本很大的不同就包括:舍弃掉了某些方法:比如
以前是这样玩的: [hud showAnimated:YES whileExecutingBlock:^{
float progress = 0.0f;
while (progress < 1.0f) {
progress += 0.01f;
hud.progress = progress;
usleep(50000);
}
} completionBlock:^{
[hud removeFromSuperview];
hud = nil;
}];
现在不行了,得像下边这样玩:
|
|
* | *
* *
*
**/ dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
float progress = 0.0f;
while (progress < 1.0f) {
progress += 0.01f;
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD HUDForView:self.view].progress = progress;
});
usleep(50000);
} dispatch_async(dispatch_get_main_queue(), ^{
[hud hideAnimated:YES];
});
});
}
//自定义视图
- (void)custonView:(MBProgressHUD *)hud{
NSMutableArray *contingentArray =[NSMutableArray array];
for (int i=1; i<13; i++) {
NSString *imgName =[NSString stringWithFormat:@"%d",i];
UIImage *image;
if (iOS7) {
image =[[UIImage imageNamed:imgName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
}else{
image =[UIImage imageNamed:imgName];
} [contingentArray addObject:image];
} UIImageView *hudImageView =[[UIImageView alloc] init];
hudImageView.animationImages =contingentArray; //UIImageView的动画组
hudImageView.animationDuration= 1.0; //每次动画的执行时间
hudImageView.animationRepeatCount = 0; //设置动画次数,0表示无限
[hudImageView startAnimating]; //开始动画
hud.customView = hudImageView; //自定义的视图,将会展示为HUD效果 [hud hideAnimated:YES afterDelay:10.0f]; //10s后隐藏HUD } #pragma mark -MBProgressHUDDelegate
- (void)hudWasHidden:(MBProgressHUD *)hud {
[hud removeFromSuperview];
hud = nil;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
MBProgressHUD基础用法的更多相关文章
- PropertyGrid控件由浅入深(二):基础用法
目录 PropertyGrid控件由浅入深(一):文章大纲 PropertyGrid控件由浅入深(二):基础用法 控件的外观构成 控件的外观构成如下图所示: PropertyGrid控件包含以下几个要 ...
- logstash安装与基础用法
若是搭建elk,建议先安装好elasticsearch 来自官网,版本为2.3 wget -c https://download.elastic.co/logstash/logstash/packag ...
- elasticsearch安装与基础用法
来自官网,版本为2.3 注意elasticsearch依赖jdk,2.3依赖jdk7 下载rpm包并安装 wget -c https://download.elastic.co/elasticsear ...
- BigDecimal最基础用法
BigDecimal最基础用法 用字符串生成的BigDecimal是不会丢精度的. 简单除法. public class DemoBigDecimal { public static void mai ...
- Vue组件基础用法
前面的话 组件(Component)是Vue.js最强大的功能之一.组件可以扩展HTML元素,封装可重用的代码.根据项目需求,抽象出一些组件,每个组件里包含了展现.功能和样式.每个页面,根据自己所需, ...
- Smarty基础用法
一.Smarty基础用法: 1.基础用法如下 include './smarty/Smarty.class.php';//引入smarty类 $smarty = new Smarty();//实例化s ...
- 前端自动化测试神器-Katalon的基础用法
前言 最近由于在工作中需要通过Web端的功能进行一次大批量的操作,数据量大概在5000左右,如果手动处理, 完成一条数据的操作用时在20秒左右的话,大概需要4-5个人/天的工作量(假设一天8小时的工作 ...
- Bootstrap fileinput:文件上传插件的基础用法
官网地址:http://plugins.krajee.com/ 官网提供的样例:http://plugins.krajee.com/file-input/demo 基础用法一 导入核心CSS及JS文件 ...
- asyncio 基础用法
asyncio 基础用法 python也是在python 3.4中引入了协程的概念.也通过这次整理更加深刻理解这个模块的使用 asyncio 是干什么的? asyncio是Python 3.4版本引入 ...
随机推荐
- MVC通过服务端对数据进行验证(和AJAX验证一样)
在实体类中 添加 Remote属性,指定用某个View下的某个方法进行验证,如下面表示用User控制器中的UserExiting方法验证 public class User { [Remot ...
- Linux用户及权限分配
一.用户分类 所有者 u; 所属组 g; 其它用户 o; 所有用户 a; 二.用户管理 //查看用户 id user //添加用户 useradd user //设置密码 passwd user // ...
- Docker-Compose 一键部署Ningx+.Net Core+Redis集群
在看该文章前,你需要对Docker有所了解. 1.创建WebApp应用程序 我使用的是.Net Core 1.0.1版本,创建一个MVC应用程序,并添加对Redis的引用.因为这些很基础,也很简单,这 ...
- springMVC多视图的支持
1.在springmvc.xml中加上 <!-- 多视图的支持 --> <bean class="org.springframework.web.servlet.view. ...
- install opencv
OpenCV是一个基于开源发行的跨平台计算机视觉库,它轻量级而且高效——由一系列 C 函数和少量 C++ 类构成,同时提供了Python.Ruby.MATLAB等语言的接口,实现了图像处理和计算机视觉 ...
- 独家git clone 加速方法
git clone 独家方法 最近需要下载网上很多github库,所以git clone 4kb/s 的速度可以把人逼疯,为了加速git clone才有了这篇博客 网上有很多加速的方案 比如 blog ...
- 配置了java环境变量后不起作用
我的电脑上装了好几个版本的jdk,有jdk1.6.jdk1.8.但是我的环境变量是设置jdk1.6的.然而打开cmd,查看Java版本却显示的是1.8,这让我百思不得其解.后来发现了问题. 问题:在p ...
- hdu 4857 逃生 拓扑排序+逆向建图
逃生 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Descr ...
- js 捕获型事件
true 为捕获型事件 false 为冒泡型事件
- xshell5使用ssh连接阿里云服务器
这里有两种方式,一种是在阿里云的控制台里面进行,另一种是在Xshell里面生成密钥. 阿里云控制台密钥对 点击右上方的创建密钥对 在阿里云里面生成较为简单,点击该页面右上方的“创建密钥对”,在另一个页 ...