118 lines
5.5 KiB
Objective-C
118 lines
5.5 KiB
Objective-C
//
|
|
// HUDManager.m
|
|
// TeacherPro
|
|
//
|
|
// Created by on 2017/4/24.
|
|
// Copyright © 2017年 ZNXZ. All rights reserved.
|
|
//
|
|
|
|
#import "HUDManager.h"
|
|
|
|
#import "DGActivityIndicatorView.h"
|
|
// HUD显示文字
|
|
#define HUDAutoHideTypeShowTime 2.5 // HUD自动隐藏模式显示的时间:2.5秒
|
|
static MBProgressHUD *HUD;
|
|
@implementation HUDManager
|
|
|
|
+ (void)showAutoHideHUDWithToShowStr:(NSString *)showStr{
|
|
[self showAutoHideHUDWithToShowStr:showStr HUDAddedToView:[UIApplication sharedApplication].windows.firstObject];
|
|
}
|
|
+ (void)showAutoHideHUDWithToShowStr:(NSString *)showStr HUDAddedToView:(UIView *)superView
|
|
{
|
|
[self showHUDWithToShowStr:showStr HUDMode:MBProgressHUDModeText autoHide:YES afterDelay:HUDAutoHideTypeShowTime userInteractionEnabled:YES HUDAddedToView:superView addProgress:0.0f];
|
|
}
|
|
+ (void)showAutoHideHUDWithToShowStr:(NSString *)showStr HUDMode:(MBProgressHUDMode)mode HUDAddedToView:(UIView *)superView
|
|
{
|
|
[self showHUDWithToShowStr:showStr HUDMode:mode autoHide:YES afterDelay:HUDAutoHideTypeShowTime userInteractionEnabled:YES HUDAddedToView:superView addProgress:0.0f];
|
|
}
|
|
+ (void)showAutoHideHUDOfCustomViewWithToShowStr:(NSString *)showStr showType:(HUDShowType)showType HUDAddedToView:(UIView *)superView addProgress:(CGFloat)progress
|
|
{
|
|
[self showHUDWithToShowStr:showStr HUDMode:MBProgressHUDModeCustomView autoHide:YES afterDelay:HUDAutoHideTypeShowTime userInteractionEnabled:YES showType:showType HUDAddedToView:superView addProgress:progress hasShade:YES];
|
|
}
|
|
+ (void)showHUDWithToShowStr:(NSString *)showStr HUDMode:(MBProgressHUDMode)mode autoHide:(BOOL)autoHide afterDelay:(NSTimeInterval)afterDelay userInteractionEnabled:(BOOL)yesOrNo HUDAddedToView:(UIView *)superView addProgress:(CGFloat)progress
|
|
{
|
|
[self showHUDWithToShowStr:showStr HUDMode:mode autoHide:autoHide afterDelay:afterDelay userInteractionEnabled:yesOrNo showType:HUDOthers HUDAddedToView:superView addProgress:progress hasShade:YES];
|
|
}
|
|
|
|
+ (void)showActivityHUDToView:(UIView *)superView {
|
|
[self showHUDWithToShowStr:@"" HUDMode:MBProgressHUDModeCustomView autoHide:NO afterDelay:1 userInteractionEnabled:NO showType:HUDOthers HUDAddedToView:superView addProgress:1 hasShade:YES];
|
|
}
|
|
|
|
+ (void)showActivityHUD{
|
|
[self showActivityHUDToView:[UIApplication sharedApplication].keyWindow];
|
|
}
|
|
+ (void)showCustomViewHUDWithToShowStr:(NSString *)showStr
|
|
{
|
|
[self showHUDWithToShowStr:showStr HUDMode:MBProgressHUDModeCustomView autoHide:NO afterDelay:1 userInteractionEnabled:NO showType:HUDOthers HUDAddedToView:[UIApplication sharedApplication].keyWindow addProgress:1 hasShade:YES];
|
|
}
|
|
|
|
+ (void)showCustomViewHUDWithToShowStr:(NSString *)showStr HUDAddedToView:(UIView *)superView
|
|
{
|
|
[self showHUDWithToShowStr:showStr HUDMode:MBProgressHUDModeCustomView autoHide:NO afterDelay:1 userInteractionEnabled:NO showType:HUDOthers HUDAddedToView:superView addProgress:1 hasShade:YES];
|
|
}
|
|
|
|
+ (void)showHUDWithToShowStr:(NSString *)showStr HUDMode:(MBProgressHUDMode)mode autoHide:(BOOL)autoHide afterDelay:(NSTimeInterval)afterDelay userInteractionEnabled:(BOOL)yesOrNo showType:(HUDShowType)showType HUDAddedToView:(UIView *)superView addProgress:(CGFloat)progress hasShade:(BOOL)showShadeState
|
|
{
|
|
// 隐藏上一次显示的hud
|
|
[self hideHUD];
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
if (!HUD) {
|
|
HUD = [[MBProgressHUD alloc] initWithView:superView];
|
|
HUD.removeFromSuperViewOnHide = YES;
|
|
[superView addSubview:HUD];
|
|
}
|
|
HUD.userInteractionEnabled = !yesOrNo; // 加上这个属性才能在HUD还没隐藏的时候点击到别的view
|
|
HUD.mode = mode;
|
|
if (mode == MBProgressHUDModeCustomView)
|
|
{
|
|
// UIImageView *customImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
|
|
// HUD.customView = customImgView;
|
|
|
|
UIColor *tintColor = [UIColor colorWithRed:255.0/255.0 green: 81.0/255.0 blue: 86.0/255.0 alpha:1];
|
|
|
|
DGActivityIndicatorView *activityIndicatorView = [[DGActivityIndicatorView alloc] initWithType: DGActivityIndicatorAnimationTypeNineDots tintColor:tintColor];
|
|
CGFloat width = superView.bounds.size.width / 5.0f;
|
|
CGFloat height = superView.bounds.size.height / 7.0f;
|
|
activityIndicatorView.frame = CGRectMake(0, 0, width, height);
|
|
[activityIndicatorView startAnimating];
|
|
HUD.customView = activityIndicatorView;
|
|
HUD.customView.tintColor = tintColor;
|
|
|
|
}else if (mode == MBProgressHUDModeDeterminate){
|
|
|
|
HUD.progress = progress;
|
|
|
|
}else if (mode == MBProgressHUDModeText){
|
|
|
|
}
|
|
|
|
HUD.detailsLabel.text = showStr;
|
|
// HUD.color = [UIColor blackColor]
|
|
// HUD.taskInProgress = YES;
|
|
HUD.animationType = MBProgressHUDAnimationZoomOut;
|
|
[HUD showAnimated:YES];
|
|
|
|
if (autoHide)
|
|
{
|
|
[HUD hideAnimated: YES afterDelay:afterDelay];
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
+ (void)hideHUD
|
|
{
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
if (HUD.mode == MBProgressHUDModeCustomView) {
|
|
[(DGActivityIndicatorView *)HUD.customView stopAnimating];
|
|
}
|
|
[HUD hideAnimated:YES];
|
|
[HUD removeFromSuperview];
|
|
HUD = nil;
|
|
});
|
|
}
|
|
|
|
@end
|