LoadingView.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. //
  2. // LoadingView.m/Users/apple/Desktop/jiaPei/jiaPei/SearchBase.m
  3. //
  4. // Created by apple on 15/11/11.
  5. // Copyright (c) 2015年 JCZ. All rights reserved.
  6. //
  7. #import "LoadingView.h"
  8. #import "STButton.h"
  9. #import <AVFoundation/AVFoundation.h>
  10. #import <MBProgressHUD/MBProgressHUD.h>
  11. static LoadingView* myView ;
  12. static NSMutableArray* msgArr;
  13. /**用来播放水滴声音的
  14. */
  15. static AVAudioPlayer* player;
  16. #define HUD_Frame [[UIScreen mainScreen] bounds]
  17. #define HUD_Size HUD_Frame.size
  18. @interface LoadingView()
  19. @end
  20. @implementation LoadingView
  21. +(void)makeVoice
  22. {
  23. NSString * path = [[NSBundle mainBundle] pathForResource:@"toast.wav" ofType:nil];
  24. NSFileManager* fm = [NSFileManager defaultManager];
  25. if (![fm fileExistsAtPath:path]) {
  26. return;
  27. }
  28. NSURL * url = [NSURL fileURLWithPath:path];
  29. player =[[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];
  30. player.volume = 1;
  31. player.numberOfLoops =0;
  32. if (player.playing) {
  33. return;
  34. }
  35. [player play];
  36. }
  37. /**如果真机上遇到MSG无法消除的问题。可以考虑用数组保存label。然后遍历数组移除。
  38. 无法消除问题 --danson
  39. */
  40. +(void)showMsg:(NSString*)str
  41. {
  42. dispatch_async(dispatch_get_main_queue(), ^{
  43. [self makeVoice];
  44. // 快速显示一个提示信息
  45. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
  46. hud.detailsLabel.text = str;
  47. //模式
  48. hud.mode = MBProgressHUDModeText;
  49. // 隐藏时候从父控件中移除
  50. hud.removeFromSuperViewOnHide = YES;
  51. hud.userInteractionEnabled = NO;
  52. [hud hideAnimated:YES afterDelay:3];
  53. });
  54. }
  55. /**0是普通的警告。1是操作成功的
  56. */
  57. +(void)showMsg:(NSString *)str Style:(int)style
  58. {
  59. dispatch_async(dispatch_get_main_queue(), ^{
  60. [self makeVoice];
  61. if (0 == style) {
  62. [MBProgressHUD showError:str toView:nil];
  63. }else{
  64. [MBProgressHUD showSuccess:str toView:nil];
  65. }
  66. });
  67. }
  68. //网络加载
  69. + (void)showHUD {
  70. dispatch_async(dispatch_get_main_queue(), ^{
  71. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
  72. hud.userInteractionEnabled = NO;
  73. });
  74. }
  75. //移除加载
  76. + (void)removeHUD {
  77. dispatch_async(dispatch_get_main_queue(), ^{
  78. [MBProgressHUD hideHUDForView:[UIApplication sharedApplication].keyWindow animated:NO];
  79. });
  80. }
  81. @end
  82. #pragma mark -
  83. void ShowHUD() {
  84. [LoadingView showHUD];
  85. }
  86. void RemoveHUD() {
  87. [LoadingView removeHUD];
  88. }
  89. void ShowMsg(NSString* str)
  90. {
  91. [LoadingView showMsg:str];
  92. }
  93. void showMsgUnconnect(){
  94. [LoadingView showMsg:@"网络未连接"];
  95. }
  96. void ShowMsgUnOpen()
  97. {
  98. [LoadingView showMsg:@"暂未开放,敬请期待"];
  99. }
  100. void ShowMsgFailed()
  101. {
  102. [LoadingView showMsg:@"请求失败"];
  103. }
  104. void ShowMsgSuc()
  105. {
  106. [LoadingView showMsg:@"操作成功" Style:1];
  107. }
  108. #pragma mark 确定弹框提示
  109. void showMsgByAlert(UIViewController *vc,NSString *str)
  110. {
  111. if (![str isKindOfClass:[NSString class]]) {
  112. str = @"异常情况";
  113. }
  114. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:str preferredStyle:UIAlertControllerStyleAlert];
  115. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
  116. [vc presentViewController:alertFind animated:true completion:nil];
  117. }
  118. void showMsgByAlertWithSureBlock(UIViewController *vc,NSString *str,BlockTypeVo sureBlock)
  119. {
  120. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:str preferredStyle:UIAlertControllerStyleAlert];
  121. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  122. if (sureBlock) {
  123. sureBlock();
  124. }
  125. }]];
  126. [vc presentViewController:alertFind animated:true completion:nil];
  127. }