123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- //
- // 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 <AVFoundation/AVFoundation.h>
- #import <MBProgressHUD/MBProgressHUD.h>
- 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];
- }
|