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. python3 驱动 PyMySQL

    Python版本: 3.5.0 MySqlDB官网只支持Python3.4,  使用第三方库PyMysql连接Mysql数据库. https://pypi.python.org/pypi/PyMySQ ...

  2. 推荐一个快速了解移植uboot以及linux到新板子上的ppt教程

    链接地址在此: https://elinux.org/images/2/2a/Schulz-how-to-support-new-board-u-boot-linux.pdf

  3. SpringMVC基于注解方式的quartz

    项目框架: SpringMVC.MyBatis.JSP 1. 首先配置spring.xml文件 <?xml version="1.0" encoding="UTF- ...

  4. PigVar: THE PIG VARIATIONS AND POSITIVE SELECTION DATABASE

    URL: http://www.ibiomedical.net/ http://103.53.216.7/ Go to aldb database. (keywords: chicken, cow, ...

  5. ADO.NET 使用DELETE语句批量删除操作,提示超时,删除失败,几种优化解决思路

    起因是如此简单的一句sql 提示:Timeout 时间已到.在操作完成之前超时时间已过或服务器未响应. 提供几种解决思路: 1.检查WHERE条件中字段是否已建索引 2.检查是否被其他表引用,引用表外 ...

  6. LA 3720 高速公路(互质判斜率)

    https://vjudge.net/problem/UVALive-3720 题意: 有一个n行m列的点阵,问一共有多少条非水平非垂直的直线至少穿过其中的两个点. 思路: 没思路的题. 首先枚举矩形 ...

  7. redis 与session

    springboot:session集中存储到redis https://www.cnblogs.com/huiy/p/6907164.html springboot处理session生命周期 htt ...

  8. 从源码角度分析 Kotlin by lazy 的实现

    by lazy 的作用 延迟属性(lazy properties) 是 Kotlin 标准库中的标准委托之一,可以通过 by lazy 来实现. 其中,lazy() 是一个函数,可以接受一个 Lamb ...

  9. jquery tmpl模板

    之前用模板渲染都是用angular,无意间发现了jquery tmpl这种轻量级,其文档在这里 官方解释对该插件的说明:将匹配的第一个元素作为模板,render指定的数据,签名如下: .tmpl([d ...

  10. LeetCode第[88]题(Java):Merge Sorted Array(合并已排序数组)

    题目:合并已排序数组 难度:Easy 题目内容: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as ...