ShareAlertView.m
5.3 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
//
// ShareAlertView.m
// DreamSleep
//
// Created by peter on 2022/4/24.
//
#import "ShareAlertView.h"
@interface ShareAlertView ()
@property (nonatomic, strong) UIView *shareView;
@end
@implementation ShareAlertView
- (instancetype)initWithDelegate:(id<ShareAlertViewDelegate>)delegate shareSource:(ShareSource)shareSource {
if (self = [super initWithFrame:[UIScreen mainScreen].bounds]) {
_delegate = delegate;
_shareSource = shareSource;
self.backgroundColor = AlertDarkColor;
self.backgroundColor = [self.backgroundColor colorWithAlphaComponent:0.6];
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
[self addGestureRecognizer:tapGR];
[self addSubview:self.shareView];
[self.shareView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.left.equalTo(self).offset(15);
make.right.equalTo(self).offset(-15);
make.bottom.equalTo(self).offset(- 118 - Bottom_SafeArea_Height);
make.height.equalTo(@125);
}];
UILabel *titleLab = [UILabel dkLabWithText:@"分享到" font:BoldFont(15)];
[self.shareView addSubview:titleLab];
UIButton *wxFriendBtn = [self btnWithTitle:@"微信好友" index:1 imgName:@"wx_friend" superView:self.shareView];
UIButton *wxTimelineBtn = [self btnWithTitle:@"朋友圈" index:2 imgName:@"wx_timeline" superView:self.shareView];
UIButton *qqShareBtn = [self btnWithTitle:@"QQ好友" index:3 imgName:@"qq_share" superView:self.shareView];
UIButton *dismissBtn = [UIButton dkBtnTitle:@"取消" font:BoldFont(15)];
dismissBtn.dk_backgroundColorPicker = DKColorPickerWithKey(TabBarBG);
[dismissBtn addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
[dismissBtn cornerRadius:12.0];
[self addSubview:dismissBtn];
[titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.shareView);
make.top.equalTo(self.shareView).offset(15);
make.height.equalTo(@21);
}];
[wxFriendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(titleLab.mas_bottom);
make.bottom.equalTo(self.shareView);
make.left.equalTo(self.shareView);
}];
[wxTimelineBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(wxFriendBtn);
make.left.equalTo(wxFriendBtn.mas_right);
make.size.equalTo(wxFriendBtn);
}];
[qqShareBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(wxFriendBtn);
make.left.equalTo(wxTimelineBtn.mas_right);
make.size.equalTo(wxFriendBtn);
make.right.equalTo(self.shareView);
}];
[dismissBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.shareView);
make.left.equalTo(self).offset(15);
make.right.equalTo(self).offset(-15);
make.top.equalTo(self.shareView.mas_bottom).offset(20);
make.height.equalTo(@40);
}];
}
return self;
}
#pragma mark - Actions
- (void)clickAction:(UIButton *)sender {
[self dismissShareAlertView];
NSString *step = @"点击微信好友分享按钮";
if (sender.tag == 2) {
step = @"点击朋友圈分享按钮";
} else if (sender.tag == 3) {
step = @"点击QQ好友分享按钮";
}
[DataStatisticsUtil event:InviteFriends attributes:@{@"step":step}];
if (self.delegate && [self.delegate respondsToSelector:@selector(didClickShareBtnWithIndex:shareSource:)]) {
[self.delegate didClickShareBtnWithIndex:(int)sender.tag shareSource:self.shareSource];
}
}
- (void)cancelAction {
[self dismissShareAlertView];
[DataStatisticsUtil event:InviteFriends attributes:@{@"step":@"取消分享"}];
}
- (void)tapAction:(UITapGestureRecognizer *)gesture {
if (!CGRectContainsPoint(self.shareView.frame, [gesture locationInView:self])) {
[self dismissShareAlertView];
}
}
#pragma mark - public
- (void)showShareAlertView {
[DSKeyWindow addSubview:self];
}
- (void)dismissShareAlertView {
[self removeFromSuperview];
}
#pragma mark - lazy
- (UIView *)shareView {
if (!_shareView) {
_shareView = [UIView new];
[_shareView cornerRadius:12.0];
_shareView.dk_backgroundColorPicker = DKColorPickerWithKey(TabBarBG);
}
return _shareView;
}
#pragma mark - others
- (UIButton *)btnWithTitle:(NSString *)title index:(int)index imgName:(NSString *)imgName superView:(UIView *)sv {
UIButton *btn = [UIButton btnWithTitle:title font:SysFont(12)];
[btn dk_setTitleColorPicker:DKColorPickerWithColors(SubTitleColor, DSWhite, DSWhite) forState:UIControlStateNormal];
btn.tag = index;
[btn setImage:[UIImage imageNamed:imgName] forState:UIControlStateNormal];
[btn adjustLayoutWithType:UIButtonLayoutTypeUpImageBottomTitle midSpace:2 sizeToFit:YES];
[btn addTarget:self action:@selector(clickAction:) forControlEvents:UIControlEventTouchUpInside];
[sv addSubview:btn];
return btn;
}
@end