zjf
2023-03-13 881f0da670f20c401c1e1d08b36253abb28f72d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//
//  YJProgressHUD.m
//  PictureHouseKeeper
//
//  Created by 李亚军 on 16/8/19.
//  Copyright © 2016年 zyyj. All rights reserved.
//
 
#import "YJProgressHUD.h"
 
@implementation YJProgressHUD
 
+(instancetype)shareinstance{
    
    static YJProgressHUD *instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[YJProgressHUD alloc] init];
    });
    
    return instance;
    
}
 
+(void)show:(NSString *)msg inView:(UIView *)view mode:(YJProgressMode)myMode{
    [self show:msg inView:view mode:myMode customImgView:nil];
}
 
+(void)show:(NSString *)msg inView:(UIView *)view mode:(YJProgressMode)myMode customImgView:(UIImageView *)customImgView{
    //如果为nil ,在最上层windows显示
    if (view == nil) {
        view = [[UIApplication sharedApplication].windows lastObject];
    }
    //如果已有弹框,先消失
    if ([YJProgressHUD shareinstance].hud != nil) {
        [[YJProgressHUD shareinstance].hud hideAnimated:YES];
        [YJProgressHUD shareinstance].hud = nil;
    }
    
    //4\4s屏幕避免键盘存在时遮挡
    if ([UIScreen mainScreen].bounds.size.height == 480) {
        [view endEditing:YES];
    }
    
    [YJProgressHUD shareinstance].hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    
    //这里设置是否显示遮罩层
    //[YJProgressHUD shareinstance].hud.dimBackground = YES;    //是否显示透明背景
    
    //是否设置黑色背景,这两句配合使用
    [YJProgressHUD shareinstance].hud.bezelView.color = [UIColor blackColor];
    [YJProgressHUD shareinstance].hud.contentColor = [UIColor blackColor];
    
    [[YJProgressHUD shareinstance].hud setMargin:10];
    [[YJProgressHUD shareinstance].hud setRemoveFromSuperViewOnHide:YES];
    [YJProgressHUD shareinstance].hud.detailsLabel.text = msg;
    
    [YJProgressHUD shareinstance].hud.detailsLabel.font = [UIFont systemFontOfSize:14];
    switch ((NSInteger)myMode) {
        case YJProgressModeOnlyText:
            [YJProgressHUD shareinstance].hud.mode = MBProgressHUDModeText;
            break;
            
        case YJProgressModeLoading:
            [YJProgressHUD shareinstance].hud.mode = MBProgressHUDModeIndeterminate;
            break;
            
        case YJProgressModeCircle:{
            [YJProgressHUD shareinstance].hud.mode = MBProgressHUDModeCustomView;
            UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"loading"]];
            CABasicAnimation *animation= [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
            animation.toValue = [NSNumber numberWithFloat:M_PI*2];
            animation.duration = 1.0;
            animation.repeatCount = 100;
            [img.layer addAnimation:animation forKey:nil];
            [YJProgressHUD shareinstance].hud.customView = img;
            
            
            break;
        }
        case YJProgressModeCustomerImage:
            [YJProgressHUD shareinstance].hud.mode = MBProgressHUDModeCustomView;
            [YJProgressHUD shareinstance].hud.customView = customImgView;
            break;
            
        case YJProgressModeCustomAnimation:
            //这里设置动画的背景色
            [YJProgressHUD shareinstance].hud.bezelView.color = [UIColor blackColor];
            [YJProgressHUD shareinstance].hud.mode = MBProgressHUDModeCustomView;
            [YJProgressHUD shareinstance].hud.customView = customImgView;
            
            break;
            
        case YJProgressModeSuccess:
            [YJProgressHUD shareinstance].hud.mode = MBProgressHUDModeCustomView;
            [YJProgressHUD shareinstance].hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"success"]];
            break;
            
        case YJProgressModeFailed:
            [YJProgressHUD shareinstance].hud.mode = MBProgressHUDModeCustomView;
            [YJProgressHUD shareinstance].hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"fail"]];
            break;
        default:
            break;
    }
 
}
 
 
+(void)hide{
    if ([YJProgressHUD shareinstance].hud != nil) {
        [[YJProgressHUD shareinstance].hud hideAnimated:YES];
    }
}
 
 
+(void)showMessage:(NSString *)msg inView:(UIView *)view{
    [self show:msg inView:view mode:YJProgressModeOnlyText];
    [[YJProgressHUD shareinstance].hud hideAnimated:YES afterDelay:1.5];
}
 
 
+(void)showMessage:(NSString *)msg inView:(UIView *)view afterDelayTime:(NSInteger)delay{
    [self show:msg inView:view mode:YJProgressModeOnlyText];
    [[YJProgressHUD shareinstance].hud hideAnimated:YES afterDelay:delay];
}
 
+(void)showSuccess:(NSString *)msg inview:(UIView *)view{
    [self show:msg inView:view mode:YJProgressModeSuccess];
    [[YJProgressHUD shareinstance].hud hideAnimated:YES afterDelay:1.5];
    
}
 
+(void)showFailed:(NSString *)msg inview:(UIView *)view {
    [self show:msg inView:view mode:YJProgressModeFailed];
    [[YJProgressHUD shareinstance].hud hideAnimated:YES afterDelay:1.5];
}
 
+(void)showMsgWithImage:(NSString *)msg imageName:(NSString *)imageName inview:(UIView *)view{
    UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
    [self show:msg inView:view mode:YJProgressModeCustomerImage customImgView:img];
    [[YJProgressHUD shareinstance].hud hideAnimated:YES afterDelay:1.0];
}
 
 
+(void)showProgress:(NSString *)msg inView:(UIView *)view{
    [self show:msg inView:view mode:YJProgressModeLoading];
}
 
+(MBProgressHUD *)showProgressCircle:(NSString *)msg inView:(UIView *)view{
    if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window;
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeAnnularDeterminate;
    hud.detailsLabel.text = msg;
    return hud;
    
    
}
 
+(void)showProgressCircleNoValue:(NSString *)msg inView:(UIView *)view{
    [self show:msg inView:view mode:YJProgressModeCircle];
    
}
 
 
+(void)showMsgWithoutView:(NSString *)msg{
    UIWindow *view = [[UIApplication sharedApplication].windows lastObject];
    [self show:msg inView:view mode:YJProgressModeOnlyText];
    [[YJProgressHUD shareinstance].hud hideAnimated:YES afterDelay:1.0];
    
}
 
+(void)showCustomAnimation:(NSString *)msg inview:(UIView *)view{
    NSArray *imgArry = [self getImages];
    UIImageView *showImageView = [[UIImageView alloc] init];
    showImageView.animationImages = imgArry;
    [showImageView setAnimationRepeatCount:0];
    [showImageView setAnimationDuration:(imgArry.count + 1) * 0.075];
    [showImageView startAnimating];
    
    [self show:msg inView:view mode:YJProgressModeCustomAnimation customImgView:showImageView];
    
    
}
+ (NSArray *)getImages {
    NSMutableArray *arrM = [[NSMutableArray alloc] init];
    for (int i = 1; i < 18; i ++) {
        [arrM addObject:[UIImage imageNamed:[NSString stringWithFormat:@"loading_%d",i]]];
    }
    return arrM.copy;
}
 
@end