本文主要是介绍iOS 关于MBProgressHUD的使用 自定义动画,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
MBProgressHUD的常用属性和用法:
/*要将一个MBProgressHUD显示出来,1,创建对象;2,将HUD添加到view上;3,调用show方法隐藏,1,hide:方法; 2,hide: afterDelay: 方法其它的用法都是特殊的设置等*/HUD = [[MBProgressHUD alloc] init];[self.view addSubview:HUD];
// HUD.mode = MBProgressHUDModeIndeterminate;//菊花,默认值
// HUD.mode = MBProgressHUDModeDeterminate;//圆饼,饼状图
// HUD.mode = MBProgressHUDModeDeterminateHorizontalBar;//进度条HUD.mode = MBProgressHUDModeAnnularDeterminate;//圆环作为进度条
// HUD.mode = MBProgressHUDModeCustomView; //需要设置自定义视图时候设置成这个
// HUD.mode = MBProgressHUDModeText; //只显示文本//1,设置背景框的透明度 默认0.8HUD.opacity = 1;//2,设置背景框的背景颜色和透明度, 设置背景颜色之后opacity属性的设置将会失效HUD.color = [UIColor redColor];HUD.color = [HUD.color colorWithAlphaComponent:1];//3,设置背景框的圆角值,默认是10HUD.cornerRadius = 20.0;//4,设置提示信息 信息颜色,字体HUD.labelColor = [UIColor blueColor];HUD.labelFont = [UIFont systemFontOfSize:13];HUD.labelText = @"Loading...";//5,设置提示信息详情 详情颜色,字体HUD.detailsLabelColor = [UIColor blueColor];HUD.detailsLabelFont = [UIFont systemFontOfSize:13];HUD.detailsLabelText = @"LoadingLoading...";//6,设置菊花颜色 只能设置菊花的颜色HUD.activityIndicatorColor = [UIColor blackColor];//7,设置一个渐变层HUD.dimBackground = YES;//8,设置动画的模式
// HUD.mode = MBProgressHUDModeIndeterminate;//9,设置提示框的相对于父视图中心点的便宜,正值 向右下偏移,负值左上HUD.xOffset = -80;HUD.yOffset = -100;//10,设置各个元素距离矩形边框的距离HUD.margin = 0;//11,背景框的最小大小HUD.minSize = CGSizeMake(50, 50);//12设置背景框的实际大小 readonlyCGSize size = HUD.size;//13,是否强制背景框宽高相等HUD.square = YES;//14,设置显示和隐藏动画类型 有三种动画效果,如下
// HUD.animationType = MBProgressHUDAnimationFade; //默认类型的,渐变
// HUD.animationType = MBProgressHUDAnimationZoomOut; //HUD的整个view后退 然后逐渐的后退HUD.animationType = MBProgressHUDAnimationZoomIn; //和上一个相反,前近,最后淡化消失//15,设置最短显示时间,为了避免显示后立刻被隐藏 默认是0
// HUD.minShowTime = 10;//16,/*// 这个属性设置了一个宽限期,它是在没有显示HUD窗口前被调用方法可能运行的时间。// 如果被调用方法在宽限期内执行完,则HUD不会被显示。// 这主要是为了避免在执行很短的任务时,去显示一个HUD窗口。// 默认值是0。只有当任务状态是已知时,才支持宽限期。具体我们看实现代码。@property (assign) float graceTime;// 这是一个标识位,标明执行的操作正在处理中。这个属性是配合graceTime使用的。// 如果没有设置graceTime,则这个标识是没有太大意义的。在使用showWhileExecuting:onTarget:withObject:animated:方法时,// 会自动去设置这个属性为YES,其它情况下都需要我们自己手动设置。@property (assign) BOOL taskInProgress;*///17,设置隐藏的时候是否从父视图中移除,默认是NOHUD.removeFromSuperViewOnHide = NO;//18,进度指示器 模式是0,取值从0.0————1.0
// HUD.progress = 0.5;//19,隐藏时候的回调 隐藏动画结束之后HUD.completionBlock = ^(){NSLog(@"abnnfsfsf");};//设置任务,在hud上显示任务的进度[HUD showWhileExecuting:@selector(myProgressTask) onTarget:self withObject:nil animated:YES];// [HUD show:YES];//两种隐藏的方法
// [HUD hide:YES];[HUD hide:YES afterDelay:5];}//任务,测试进度显示
- (void)myProgressTask {// This just increases the progress indicator in a loopfloat progress = 0.0f;while (progress < 1.0f) {progress += 0.01f;HUD.progress = progress;usleep(50000);}
}
更多详解参见:
http://www.cnblogs.com/liuting-1204/p/5996465.html
自定义加载动画有两种方法:
1、把模式改为自定义视图,图片使用了SDWebImage加载gif图的方法:
#import "UIImage+GIF.h"
#import "MBProgressHUD.h"
#pragma mark - 自定义MBProgressHUD动画
-(void)customProgressHUD
{MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];hud.mode = MBProgressHUDModeCustomView;UIImageView *gifImageView = [[UIImageView alloc] initWithImage:[UIImage sd_animatedGIFNamed:@"meinv"]];hud.customView = gifImageView;hud.color = [UIColor clearColor];
}
2、还是模式为自定义视图,采用UIImageView的动画效果:
- (void)showHudInView:(UIView *)view hint:(NSString *)hint{MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:view];HUD.mode = MBProgressHUDModeCustomView;
// HUD.labelText = hint;HUD.color = [UIColor clearColor];//自定义动画UIImageView *gifImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sLoading_1"]];NSMutableArray *arrM = [[NSMutableArray alloc] init];for (int i = 0; i < 12; i ++) {UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"sLoading_%d", i + 1]];[arrM addObject:image];}[gifImageView setAnimationImages:arrM];[gifImageView setAnimationDuration:1.5];[gifImageView setAnimationRepeatCount:0];[gifImageView startAnimating];HUD.customView = gifImageView;[view addSubview:HUD];[HUD show:YES];[self setHUD:HUD];
}
这篇关于iOS 关于MBProgressHUD的使用 自定义动画的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!