之前用过MBProgressHUD和SVProgressHUD,两个第三方都挺好用
最近使用MBProgressHUD一直报让使用GCD
'showAnimated:whileExecutingBlock:completionBlock:' is deprecated: Use GCD directly.
MBProgressHUD官网的地址: https://github.com/jdg/MBProgressHUD
可以按照官网上进行修改
-(void)createMBProgressHUD
{
MBProgressHUD *HUD =[MBProgressHUD showHUDAddedTo:self.view animated:YES]; //HUD的创建
// HUD.mode = MBProgressHUDModeIndeterminate;//菊花,默认值
// HUD.mode = MBProgressHUDModeDeterminate;//圆饼,饼状图
// HUD.mode = MBProgressHUDModeDeterminateHorizontalBar;//进度条
HUD.mode = MBProgressHUDModeAnnularDeterminate;//圆环作为进度条
// HUD.mode = MBProgressHUDModeCustomView; //需要设置自定义视图时候设置成这个
// HUD.mode = MBProgressHUDModeText; //只显示文本
HUD.label.text = @"正在加载中..."; // 标题(加载时的提示文字)
HUD.detailsLabel.text = @"一直在奔跑"; // 副标题
HUD.delegate = self; // 使hud消失时能清理对象,省出内存
//1,设置各个元素距离矩形边框的距离
HUD.margin = 0;
//2,背景框的最小大小
HUD.minSize = CGSizeMake(50, 50);
//3,是否强制背景框宽高相等
HUD.square = YES;
//4,设置显示和隐藏动画类型 有三种动画效果,如下
// HUD.animationType = MBProgressHUDAnimationFade; //默认类型的,渐变
// HUD.animationType = MBProgressHUDAnimationZoomOut; //HUD的整个view后退 然后逐渐的后退
// HUD.animationType = MBProgressHUDAnimationZoomIn; //和上一个相反,前近,最后淡化消失
//5,设置最短显示时间,为了避免显示后立刻被隐藏 默认是0
// HUD.minShowTime = 10;
//6,设置隐藏的时候是否从父视图中移除,默认是NO
HUD.removeFromSuperViewOnHide = NO;
//7,进度指示器 模式是0,取值从0.0————1.0
// HUD.progress = 0.5;
//8,隐藏时候的回调 隐藏动画结束之后
HUD.completionBlock = ^(){
NSLog(@"abnnfsfsf");
};
[self animationHud:HUD]; MBProgressHUD自带HUD效果
}
//MBProgressHUD
- (void)animationHud:(MBProgressHUD *)hud {
/**
MBProgressHUD 有一些方法已经不能用了:比如
[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];
});
});
}
#pragma mark -MBProgressHUDDelegate
- (void)hudWasHidden:(MBProgressHUD *)hud {
[hud removeFromSuperview];
hud = nil;
}