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版本引入 ...
随机推荐
- Python面试题之Python生成器
首先说明一下生成器也是迭代器,也有迭代器的那些优点. 那为什么要生成器呢?因为到目前为止都 不是你写的迭代器,都是别人定义好的.那如何自己去造一个迭代器呢?下面的内容就会给你答案. 想要自己造一个迭代 ...
- nginx之rewrite匹配需求
现在需求如下: nginx上配有aaa.example.com的虚拟主机,现在需要将访问http://aaa.example.com/api/x.x/client/的请求转到http://bbb.ex ...
- [BZOJ1722]Milk Team Select 产奶比赛
Description Farmer John's N (1 <= N <= 500) cows are trying to select the milking team for the ...
- Azure Active Directory配置java应用的单点登录
下载应用:https://github.com/Azure-Samples/active-directory-java-webapp-openidconnect(普通项目,集成了特殊配置接入微软的注册 ...
- 客户端发一个post请求
public static String doPostStr(String httpUrl, String str) { HttpPost httpPost = null; try { HttpCli ...
- layer弹出层的关闭及父页面的刷新问题
当在主页面执行添加或修改时,用弹出层是比较好的选择,如何关闭弹出层并对父级页面进行操作呢 首先在父级页面中打开一个添加页面(弹出层) 在添加页面的表单提交函数中添加如下代码: function for ...
- JAVA小工具打包
D: cd D:\xxx\IPOSpider javac -d bin/ src/com/xxx/IPOSpider.java src/com/xxx/ConfigProperties.java -c ...
- vscode + angular
0.在命令行中,cd到项目下执行: npm install 1.调试->启动调试->node.js, 会生成.vscode/launch.json文件 2.修改launch.json文件& ...
- 开机启动服务(ftp、apache、mysql)
当linux服务器开机时,会将 /etc/rc.d/rc.local 中的指令全部执行一遍, 因此将相应服务的启动指令放到该shell脚本中即可实现开机启动效果; 在 /etc/rc.d/rc.loc ...
- 利用python 模块读取csv文件信息
还有一个比较简单的方法 # -*- coding=utf-8 -*- import pandas as pddf = pd.read_csv("20170320094630.csv" ...