RescuePlanView.m
1.9 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
//
// RescuePlanView.m
// DreamSleep
//
// Created by peter on 2022/4/25.
//
#import "RescuePlanView.h"
@interface RescuePlanView ()
/// 拯救计划弹框图片
@property (nonatomic, strong) UIImageView *rescueIV;
/// 关闭按钮
@property (nonatomic, strong) UIButton *closeBtn;
@end
@implementation RescuePlanView
- (instancetype)initWithJumpBlock:(JumpBlock)block {
if (self = [super initWithFrame:[UIScreen mainScreen].bounds]) {
_block = block;
self.backgroundColor = DarkColor;
self.backgroundColor = [self.backgroundColor colorWithAlphaComponent:0.6];
[self addSubview:self.rescueIV];
[self addSubview:self.closeBtn];
[self.rescueIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self);
}];
[self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.rescueIV);
make.top.equalTo(self.rescueIV).offset(24);
}];
}
return self;
}
#pragma mark - Actions
- (void)show {
[DSKeyWindow addSubview:self];
}
- (void)dismiss {
[self removeFromSuperview];
}
- (void)tapAction {
[self dismiss];
if (self.block) { self.block(); }
}
#pragma mark - lazy
- (UIImageView *)rescueIV {
if (!_rescueIV) {
_rescueIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pic_pop_normal"]];
_rescueIV.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
[_rescueIV addGestureRecognizer:tapGR];
}
return _rescueIV;
}
- (UIButton *)closeBtn {
if (!_closeBtn) {
_closeBtn = [UIButton new];
[_closeBtn setImage:[UIImage imageNamed:@"home_close"] forState:UIControlStateNormal];
[_closeBtn addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
}
return _closeBtn;
}
@end