// // HUDManager.m // SunnyFace // // Created by 龚 俊慧 on 13-1-21. // Copyright (c) 2013年 龚 俊慧. All rights reserved. // #import "HUDManager.h" #import "AppDelegate.h" //static HUDManager *staticHUDManager; static MBProgressHUD *HUD; @implementation HUDManager //+ (HUDManager *)shareHUDManager //{ // //} + (void)showHUDWithToShowStr:(NSString *)showStr HUDMode:(MBProgressHUDMode)mode autoHide:(BOOL)autoHide afterDelay:(NSTimeInterval)afterDelay userInteractionEnabled:(BOOL)yesOrNo { if (!HUD) { AppDelegate *delegate =(AppDelegate *) [UIApplication sharedApplication].delegate; HUD = [[MBProgressHUD alloc] initWithFrame:delegate.window.frame]; [delegate.window addSubview:HUD]; } HUD.userInteractionEnabled = YES;//加上这个属性才能在HUD还没隐藏的时候点击到别的view // HUD.delegate = self; HUD.mode = mode; // HUD.labelText = showStr; HUD.detailsLabelText = showStr; [HUD show:YES]; // [HUD showAnimated:YES whileExecutingBlock:^{ // sleep(2);//这个是2秒后隐藏 // } completionBlock:^{ // [HUD removeFromSuperview]; // [HUD release]; // HUD = nil; // }]; if (autoHide) { [HUD hide:YES afterDelay:afterDelay]; } // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(afterDelay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // [self hideHUD]; // }); } +(void)showAlersWithTopView:(UIView *)addView Content:(NSString *)content{ HUD = [[MBProgressHUD alloc] initWithFrame:addView.frame]; [addView addSubview:HUD]; HUD.mode = MBProgressHUDModeText; HUD.userInteractionEnabled = YES;//加上这个属性才能在HUD还没隐藏的时候点击到别的view HUD.detailsLabelText = content; [HUD show:YES]; [HUD showAnimated:YES whileExecutingBlock:^{ sleep(2);//这个是2秒后隐藏 } completionBlock:^{ [HUD removeFromSuperview]; HUD = nil; }]; } +(void)showMBProgressMBProgressHUDModeText:(NSString *)str{ AppDelegate *delegate =(AppDelegate *) [UIApplication sharedApplication].delegate; HUD = [[MBProgressHUD alloc] initWithFrame:delegate.window.frame]; [delegate.window addSubview:HUD]; HUD.mode = MBProgressHUDModeText; HUD.userInteractionEnabled = YES;//加上这个属性才能在HUD还没隐藏的时候点击到别的view HUD.detailsLabelText = str; [HUD show:YES]; [HUD showAnimated:YES whileExecutingBlock:^{ sleep(2);//这个是2秒后隐藏 } completionBlock:^{ [HUD removeFromSuperview]; HUD = nil; }]; } +(void)showMBProgressHUDModeIndeterminate:(NSString *)str TopView:(UIView *)addView{ // AppDelegate *delegate =(AppDelegate *) [UIApplication sharedApplication].delegate; HUD = [[MBProgressHUD alloc] initWithFrame:addView.frame]; [addView addSubview:HUD]; HUD.mode = MBProgressHUDModeIndeterminate; HUD.userInteractionEnabled = YES;//加上这个属性才能在HUD还没隐藏的时候点击到别的view HUD.detailsLabelText = str; [HUD show:YES]; // [HUD showAnimated:YES whileExecutingBlock:^{ // sleep(2);//这个是2秒后隐藏 // } completionBlock:^{ // [HUD removeFromSuperview]; // // HUD = nil; // }]; } + (void)hideHUD { if (!HUD.hidden) [HUD hide:YES afterDelay:0.1]; [HUD removeFromSuperview]; HUD = nil; } //- (void)hudWasHidden:(MBProgressHUD *)hud //{ // [hud release]; // //} @end