CloseAlertView.m
7.1 KB
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
194
195
196
197
198
199
//
// CloseAlertView.m
// DreamSleep
//
// Created by peter on 2022/4/20.
//
#import "CloseAlertView.h"
@interface CloseAlertView ()
@property (nonatomic, strong) UIView *alertView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIImageView *cryIV;
@property (nonatomic, strong) UILabel *redLab;
@property (nonatomic, strong) UIView *dealView;
@property (nonatomic, strong) UIButton *closeBtn;
@property (nonatomic, strong) NSTimer *closeTimer;
@property (nonatomic, assign) int totalSecond;
@end
@implementation CloseAlertView
- (instancetype)initWithDelegate:(id<CloseAlertViewDelegate>)delegate {
if (self = [super initWithFrame:[UIScreen mainScreen].bounds]) {
_delegate = delegate;
_totalSecond = 10;
self.dk_backgroundColorPicker = DKColorPickerWithColors(ColorFromHex(0x6F7587), DSClearColor, DSWhite);
self.backgroundColor = [self.backgroundColor colorWithAlphaComponent:0.6];
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
[self addGestureRecognizer:tapGR];
[self addSubview:self.alertView];
[self.alertView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self);
make.width.equalTo(@280);
make.height.equalTo(@467);
}];
}
return self;
}
- (void)dealloc {
[_closeTimer invalidate];
_closeTimer = nil;
}
#pragma mark - public
- (void)showCloseUserAlertView {
[DSKeyWindow addSubview:self];
[self.closeTimer setFireDate:[NSDate date]];
}
- (void)dismissCloseUserAlertView {
[self removeFromSuperview];
[self.closeTimer setFireDate:[NSDate distantFuture]];
self.totalSecond = 10;
}
#pragma mark - actions
- (void)closeAction {
if (self.delegate && [self.delegate respondsToSelector:@selector(didClickCloseUserBtn)]) {
[self.delegate didClickCloseUserBtn];
}
}
- (void)cancelAction {
[self dismissCloseUserAlertView];
}
- (void)tapAction:(UITapGestureRecognizer *)gesture {
if (!CGRectContainsPoint(self.alertView.frame, [gesture locationInView:self])) {
[self dismissCloseUserAlertView];
}
}
#pragma mark - lazy
- (UIView *)alertView {
if (!_alertView) {
_alertView = [UIView new];
[_alertView cornerRadius:20.0];
_alertView.dk_backgroundColorPicker = DKColorPickerWithColors(DSWhite, AlertDarkColor, DSWhite);
[_alertView addSubview:self.titleLab];
[_alertView addSubview:self.cryIV];
[_alertView addSubview:self.redLab];
[_alertView addSubview:self.dealView];
[self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_alertView).offset(20);
make.centerX.equalTo(_alertView);
}];
[self.cryIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.titleLab).offset(37);
make.left.equalTo(_alertView).offset(44);
make.width.equalTo(@198);
make.height.equalTo(@186);
}];
[self.redLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.cryIV.mas_bottom).offset(23);
make.left.equalTo(_alertView).offset(15);
make.right.equalTo(_alertView).offset(-15);
}];
[self.dealView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_alertView);
make.right.equalTo(_alertView);
make.bottom.equalTo(_alertView);
make.height.equalTo(@64);
}];
}
return _alertView;
}
- (UILabel *)titleLab {
if (!_titleLab) {
_titleLab = [UILabel dkLabWithText:@"确定要抛弃小梦吗?" font:BoldFont(16.0)];
}
return _titleLab;
}
- (UIImageView *)cryIV {
if (!_cryIV) {
_cryIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"closeAlertIcon"]];
_cryIV.dk_alphaPicker = DKAlphaPickerWithAlphas(1.0, .5, .8);
}
return _cryIV;
}
- (UILabel *)redLab {
if (!_redLab) {
NSString *str = @"• 您仅可注销您本人申请的账号\n\n• 注销后,账号的全部权益将被清除备份\n\n• 注销后,账号下的所有数据、记录等将无法访问或找回";
_redLab = [UILabel labWithText:str textColor:ColorFromHex(0xF04B77) font:SysFont(14.0)];
_redLab.numberOfLines = 0;
}
return _redLab;
}
- (UIView *)dealView {
if (!_dealView) {
_dealView = [UIView new];
UIButton *closeBtn = [UIButton btnWithTitle:@"注销" titleColor:BrandColor font:BoldFont(15) bgColor:DSClearColor];
[closeBtn addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
closeBtn.enabled = NO;
[_dealView addSubview:closeBtn];
self.closeBtn = closeBtn;
UIButton *cancelBtn = [UIButton btnWithTitle:@"取消" font:BoldFont(15)];
[cancelBtn dk_setTitleColorPicker:DKColorPickerWithKey(TEXT) forState:UIControlStateNormal];
[cancelBtn addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
[_dealView addSubview:cancelBtn];
UIView *line = [UIView new];
line.dk_backgroundColorPicker = DKColorPickerWithColors(DivideLineColor, DSWhite, DSWhite);
[_dealView addSubview:line];
[closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_dealView);
make.top.equalTo(_dealView);
make.bottom.equalTo(_dealView);
}];
[cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(closeBtn.mas_right);
make.right.equalTo(_dealView);
make.width.height.equalTo(closeBtn);
}];
[line mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(_dealView);
make.top.equalTo(_dealView).offset(12);
make.bottom.equalTo(_dealView).offset(-12);
make.width.equalTo(@1);
}];
}
return _dealView;
}
- (NSTimer *)closeTimer {
if (!_closeTimer) {
WS(weakSelf);
_closeTimer = [NSTimer timerWithTimeInterval:1.0 repeats:YES block:^(NSTimer * _Nonnull timer) {
if (weakSelf.totalSecond == 0) {
[weakSelf.closeTimer setFireDate:[NSDate distantFuture]];
[weakSelf.closeBtn setTitle:@"注销" font:BoldFont(15)];
[weakSelf.closeBtn setTitleColor:BrandColor forState:UIControlStateNormal];
weakSelf.closeBtn.enabled = YES;
return;
}
weakSelf.closeBtn.enabled = NO;
[weakSelf.closeBtn setTitle:[NSString stringWithFormat:@"注销(%d)", weakSelf.totalSecond] font:BoldFont(15)];
[weakSelf.closeBtn dk_setTitleColorPicker:DKColorPickerWithColors(SubTitleColor, ColorFromHexA(0xFFFFFF, .5), DSWhite) forState:UIControlStateNormal];
weakSelf.totalSecond--;
}];
[[NSRunLoop currentRunLoop] addTimer:_closeTimer forMode:NSRunLoopCommonModes];
}
return _closeTimer;
}
@end