// // LoadingView.m/Users/apple/Desktop/jiaPei/jiaPei/SearchBase.m // // Created by apple on 15/11/11. // Copyright (c) 2015年 JCZ. All rights reserved. // #import "LoadingView.h" #import "STButton.h" #import #import static LoadingView* myView ; static NSMutableArray* msgArr; /**用来播放水滴声音的 */ static AVAudioPlayer* player; #define HUD_Frame [[UIScreen mainScreen] bounds] #define HUD_Size HUD_Frame.size @interface LoadingView() @end @implementation LoadingView +(void)makeVoice { NSString * path = [[NSBundle mainBundle] pathForResource:@"toast.wav" ofType:nil]; NSFileManager* fm = [NSFileManager defaultManager]; if (![fm fileExistsAtPath:path]) { return; } NSURL * url = [NSURL fileURLWithPath:path]; player =[[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil]; player.volume = 1; player.numberOfLoops =0; if (player.playing) { return; } [player play]; } /**如果真机上遇到MSG无法消除的问题。可以考虑用数组保存label。然后遍历数组移除。 无法消除问题 --danson */ +(void)showMsg:(NSString*)str { dispatch_async(dispatch_get_main_queue(), ^{ [self makeVoice]; // 快速显示一个提示信息 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES]; hud.detailsLabel.text = str; //模式 hud.mode = MBProgressHUDModeText; // 隐藏时候从父控件中移除 hud.removeFromSuperViewOnHide = YES; hud.userInteractionEnabled = NO; [hud hideAnimated:YES afterDelay:3]; }); } /**0是普通的警告。1是操作成功的 */ +(void)showMsg:(NSString *)str Style:(int)style { dispatch_async(dispatch_get_main_queue(), ^{ [self makeVoice]; if (0 == style) { [MBProgressHUD showError:str toView:nil]; }else{ [MBProgressHUD showSuccess:str toView:nil]; } }); } //网络加载 + (void)showHUD { dispatch_async(dispatch_get_main_queue(), ^{ MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES]; hud.userInteractionEnabled = NO; }); } //移除加载 + (void)removeHUD { dispatch_async(dispatch_get_main_queue(), ^{ [MBProgressHUD hideHUDForView:[UIApplication sharedApplication].keyWindow animated:NO]; }); } @end #pragma mark - void ShowHUD() { [LoadingView showHUD]; } void RemoveHUD() { [LoadingView removeHUD]; } void ShowMsg(NSString* str) { [LoadingView showMsg:str]; } void showMsgUnconnect(){ [LoadingView showMsg:@"网络未连接"]; } void ShowMsgUnOpen() { [LoadingView showMsg:@"暂未开放,敬请期待"]; } void ShowMsgFailed() { [LoadingView showMsg:@"请求失败"]; } void ShowMsgSuc() { [LoadingView showMsg:@"操作成功" Style:1]; } #pragma mark 确定弹框提示 void showMsgByAlert(UIViewController *vc,NSString *str) { if (![str isKindOfClass:[NSString class]]) { str = @"异常情况"; } UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:str preferredStyle:UIAlertControllerStyleAlert]; [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]]; [vc presentViewController:alertFind animated:true completion:nil]; } void showMsgByAlertWithSureBlock(UIViewController *vc,NSString *str,BlockTypeVo sureBlock) { UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:str preferredStyle:UIAlertControllerStyleAlert]; [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { if (sureBlock) { sureBlock(); } }]]; [vc presentViewController:alertFind animated:true completion:nil]; }