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基础用法的更多相关文章

  1. PropertyGrid控件由浅入深(二):基础用法

    目录 PropertyGrid控件由浅入深(一):文章大纲 PropertyGrid控件由浅入深(二):基础用法 控件的外观构成 控件的外观构成如下图所示: PropertyGrid控件包含以下几个要 ...

  2. logstash安装与基础用法

    若是搭建elk,建议先安装好elasticsearch 来自官网,版本为2.3 wget -c https://download.elastic.co/logstash/logstash/packag ...

  3. elasticsearch安装与基础用法

    来自官网,版本为2.3 注意elasticsearch依赖jdk,2.3依赖jdk7 下载rpm包并安装 wget -c https://download.elastic.co/elasticsear ...

  4. BigDecimal最基础用法

    BigDecimal最基础用法 用字符串生成的BigDecimal是不会丢精度的. 简单除法. public class DemoBigDecimal { public static void mai ...

  5. Vue组件基础用法

    前面的话 组件(Component)是Vue.js最强大的功能之一.组件可以扩展HTML元素,封装可重用的代码.根据项目需求,抽象出一些组件,每个组件里包含了展现.功能和样式.每个页面,根据自己所需, ...

  6. Smarty基础用法

    一.Smarty基础用法: 1.基础用法如下 include './smarty/Smarty.class.php';//引入smarty类 $smarty = new Smarty();//实例化s ...

  7. 前端自动化测试神器-Katalon的基础用法

    前言 最近由于在工作中需要通过Web端的功能进行一次大批量的操作,数据量大概在5000左右,如果手动处理, 完成一条数据的操作用时在20秒左右的话,大概需要4-5个人/天的工作量(假设一天8小时的工作 ...

  8. Bootstrap fileinput:文件上传插件的基础用法

    官网地址:http://plugins.krajee.com/ 官网提供的样例:http://plugins.krajee.com/file-input/demo 基础用法一 导入核心CSS及JS文件 ...

  9. asyncio 基础用法

    asyncio 基础用法 python也是在python 3.4中引入了协程的概念.也通过这次整理更加深刻理解这个模块的使用 asyncio 是干什么的? asyncio是Python 3.4版本引入 ...

随机推荐

  1. jvm3---垃圾回收器算法

    .1. GC算法 .1.1. 标记-清除算法(Mark-Sweep) 1.标记出所有需要回收的对象,在标记完成后统一回收所有被标记的对象 2.在标记完成后统一回收所有被标记的对象 缺点:一个是效率问题 ...

  2. Java银行家算法

    实验存档,代码特别烂.. 测试.java package operating.test; import operating.entity.bank.Bank; import operating.ent ...

  3. Java:延迟功能的Robot在Lunix系统上会报错

    Java:延迟功能的Robot在Lunix系统上会报错 关于延迟功能的Robot: 今天开发过程中发现,本机开发好的项目,部署到Lunix服务器竟然报错!查了代码发现: Robot r = new R ...

  4. LSTM java 实现

    由于实验室事情缘故,需要将Python写的神经网络转成Java版本的,但是python中的numpy等啥包也不知道在Java里面对应的是什么工具,所以索性直接寻找一个现成可用的Java神经网络框架,于 ...

  5. lamp编译详解

    首先确认系统环境:centos6.4 min版本 1.安装需要的开发环境 yum groupinstall "Development Tools" "Server Pla ...

  6. ubuntu下apt-get的配置文件是哪个

    答:在/etc/apt/apt.conf 这个配置文件里可以指定使用代理,如: Acquire::https::proxy "http://myproxy.com:8080/";

  7. set /p= 详解

    在批处理中回显信息有两个命令,echo和set /p=<nul,它们的共同点在于都是对程序执行信息的屏幕输出,区别在于echo是换行输出,而set /p=<nul是不换行追回输出,这样说大 ...

  8. UVa 11038 有多少个0

    https://vjudge.net/problem/UVA-11038 题意: 输入两个非负整数m和n,求将m~n的所有整数写出来,一共要写多少个数字0? 思路: 举个例子来说: 12345 从右到 ...

  9. Restore IP Addresses,将字符串转换成ip地址

    问题描述: Given a string containing only digits, restore it by returning all possible valid IP address c ...

  10. docker教程目录

    为什么要用 Docker 什么是 Docker Docker 镜像 Docker容器的运用 Docker仓库 Docker如何获取镜像 CentOS 安装Docker Docker 列出镜像 Dock ...