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. Linux上db2安装

    Linux上db2安装:https://blog.csdn.net/nayanminxing/article/details/69372283

  2. 【Thinking in Java, 4e】访问权限控制

    [包:库单元] 编译单元的概念. 一个.java文件就是一个编译单元,一个编译单元只能有一个public类,编译单元中的非public类一般是用于为public类提供支持的,这些类在包外不可见. im ...

  3. CSS Box Model(盒子模型)

    CSS Box Model(盒子模型) 一.简介 所有HTML元素可以看作盒子,在CSS中,"box model"这一术语是用来设计和布局时使用. CSS盒模型本质上是一个盒子,封 ...

  4. 在vim中的复制,剪切,粘贴

    1. 剪切和粘贴 定位鼠标到剪切的开始位置 输入v键开始选择剪切的字符,或者V键是为了选择 整行 移动方向键到结束的地方 d键是剪切,y键是复制 移动鼠标到粘贴的位置 输入P是在鼠标位置前粘贴,输入p ...

  5. CentOS 7配置静态IP地址

    [root@centos1 ~]# ifconfig -bash: ifconfig: command not found 首先,习惯性的输入echo $PATH(查看当前PATH环境变量,跟DOS的 ...

  6. PHP中的_FILE_和_DIR_的区别

    <?php$dir = dirname(__FILE__);?>在PHP5.3中,增加了一个新的常量__DIR__,指向当前执行的PHP脚本所在的目录.例如当前执行的PHP文件为 /www ...

  7. ubuntu环境下nginx的编译安装以及相关设置

    一.基本的编译与安装 1.安装依赖项 sudo apt-get update sudo apt-get install build-essential zlib1g-dev libpcre3 libp ...

  8. POJ 1208 模拟

    2017-08-28 15:07:16 writer:pprp 好开心,这道题本来在集训的时候做了很长很长时间,但是还是没有做出来,但是这次的话,只花了两个小时就做出来了 好开心,这次采用的是仔细分析 ...

  9. 谈一谈URL

    作者:ManfredHu 链接:http://www.manfredhu.com/2017/08/16/22-url/index.html 声明:版权所有,转载请保留本段信息,谢谢大家 URL URL ...

  10. 深度学习中 Batch Normalization为什么效果好

    看mnist数据集上其他人的CNN模型时了解到了Batch Normalization 这种操作.效果还不错,至少对于训练速度提升了很多. batch normalization的做法是把数据转换为0 ...