AlertViewTool.m 4.22 KB
//
//  AlertViewTool.m
//  CNLiveScioLive
//
//  Created by CNLive-zxw on 2018/9/20.
//  Copyright © 2018年 CNLive. All rights reserved.
//

#import "AlertViewTool.h"

@implementation AlertViewTool
+ (void)showHUDAddedToView:(UIView *)view duration:(NSInteger)duration{
    [MBProgressHUD showHUDAddedTo:view animated:YES];
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, duration * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        // Do something...
        [MBProgressHUD hideHUDForView:view animated:YES];
    });
}

+ (void)showHUDAddedToView:(UIView *)view text:(NSString *)text duration:(NSInteger)duration{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeCustomView;
    hud.label.text = text;
    hud.label.numberOfLines = 0;
    hud.label.lineBreakMode = NSLineBreakByCharWrapping;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, duration * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        // Do something...
        [hud hideAnimated:YES];
    });
}
+ (void)showHUDAddedToView:(UIView *)view text:(NSString *)text{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeCustomView;
    hud.label.text = text;
    hud.label.numberOfLines = 0;
    hud.label.lineBreakMode = NSLineBreakByCharWrapping;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 1.5 * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        // Do something...
        [hud hideAnimated:YES];
    });
}
+ (void)showHUDAddedToView:(UIView *)view text:(NSString *)text block:(PopBlock)block{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeCustomView;
    hud.label.text = text;
    hud.label.numberOfLines = 0;
    hud.label.lineBreakMode = NSLineBreakByCharWrapping;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 1.5 * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        // Do something...
        [hud hideAnimated:YES];
        block?block():@"";
    });
}

+ (void)showHUDViewText:(NSString *)text{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[self getCurrentVC].view animated:YES];
    hud.mode = MBProgressHUDModeCustomView;
    hud.label.text =text;
    hud.label.numberOfLines = 0;
    hud.label.lineBreakMode = NSLineBreakByCharWrapping;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 1.5 * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        // Do something...
        [hud hideAnimated:YES];
    });
}

+ (void)showHUDViewText:(NSString *)text block:(PopBlock)block{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[self getCurrentVC].view animated:YES];
    hud.mode = MBProgressHUDModeCustomView;
    hud.label.text = text;
    hud.label.numberOfLines = 0;
    hud.label.lineBreakMode = NSLineBreakByCharWrapping;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 1.5 * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [hud hideAnimated:YES];
        block?block():@"";
    });
}
+ (void)showHUDViewText:(NSString *)text block:(PopBlock)block duration:(NSInteger)duration{
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[self getCurrentVC].view animated:YES];
    hud.mode = MBProgressHUDModeCustomView;
    hud.label.text = text;
    hud.label.numberOfLines = 0;
    hud.label.lineBreakMode = NSLineBreakByCharWrapping;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, duration * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [hud hideAnimated:YES];
        block?block():@"";
    });
    
}
+ (void)showHUDView{
    [MBProgressHUD showHUDAddedTo:AppKeyWindow animated:YES];
}

+ (void)hideHUDView{
    [MBProgressHUD hideHUDForView:AppKeyWindow animated:YES];
}

+ (UIViewController *)getCurrentVC{
    UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
    
    while (topController.presentedViewController) {
        topController = topController.presentedViewController;
    }
    
    return topController;
}

@end