PosterScrollView.m
6.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
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
//
// PosterScrollView.m
// DreamSleep
//
// Created by peter on 2022/6/10.
//
#import "PosterScrollView.h"
#import "CWCarousel.h"
@interface PosterScrollView () <CWCarouselDatasource, CWCarouselDelegate>
@property (nonatomic, strong) UIView *assistView;
@property (nonatomic, strong) CWCarousel *posterView;
@property (nonatomic, strong) UIImageView *bottomIV;
@property (nonatomic, strong) UIView *inviteView;
@property (nonatomic, strong) NSArray *posterList;
@property (nonatomic, assign) NSInteger currentIndex;
@end
@implementation PosterScrollView
- (instancetype)initWithFrame:(CGRect)frame shareDelegate:(id<PosterScrollViewDelegate>)shareDelegate {
if (self = [super initWithFrame:frame]) {
self.shareDelegate = shareDelegate;
self.posterList = [NSArray array];
self.currentIndex = 0;
self.showsVerticalScrollIndicator = NO;
[self addSubview:self.assistView];
[self.assistView addSubview:self.posterView];
[self.assistView addSubview:self.inviteView];
[self.assistView addSubview:self.bottomIV];
[self.assistView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.offset(0);
make.width.equalTo(self.mas_width);
}];
[self.posterView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.assistView).offset(40);
make.width.mas_equalTo(self.assistView);
make.height.mas_equalTo(1299*(kScreenWidth - 2*58)/780.0);
}];
[self.inviteView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.assistView).offset(15);
make.right.equalTo(self.assistView).offset(-15);
make.top.equalTo(self.posterView.mas_bottom).offset(20);
make.height.equalTo(@40);
}];
[self.bottomIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.assistView);
make.top.equalTo(self.inviteView.mas_bottom).offset(7);
make.bottom.equalTo(self.assistView);
}];
[self.assistView layoutIfNeeded];
self.contentSize = CGSizeMake(kScreenWidth, self.assistView.height);
}
return self;
}
- (void)refreshPosterData:(NSArray *)listData {
self.posterList = listData;
[self.posterView freshCarousel];
}
#pragma mark - CWCarouselDatasource
- (NSInteger)numbersForCarousel {
return self.posterList.count;
}
- (UICollectionViewCell *)viewForCarousel:(CWCarousel *)carousel indexPath:(NSIndexPath *)indexPath index:(NSInteger)index {
UICollectionViewCell *cell = [carousel.carouselView dequeueReusableCellWithReuseIdentifier:@"PosterBarnnerCellID" forIndexPath:indexPath];
UIImageView *imgView = [cell.contentView viewWithTag:777];
if (!imgView) {
imgView = [[UIImageView alloc] initWithFrame:cell.contentView.bounds];
imgView.tag = 777;
imgView.contentMode = UIViewContentModeScaleAspectFit;
[cell.contentView addSubview:imgView];
}
[imgView cornerRadius:24.0];
imgView.dk_alphaPicker = DKAlphaPickerWithAlphas(1.0, .5, 1.0);
ShareItem *item = self.posterList[index];
[imgView yy_setImageWithURL:[NSURL URLWithString:item.image_url] placeholder:[UIImage imageNamed:@"bannerPlaceholder"]];
return cell;
}
#pragma mark - CWCarouselDelegate
- (void)CWCarousel:(CWCarousel *)carousel didEndScrollAtIndex:(NSInteger)index indexPathRow:(NSInteger)indexPathRow {
self.currentIndex = index;
}
#pragma mark - lazy
- (UIView *)assistView {
if (!_assistView) {
_assistView = [UIView new];
}
return _assistView;
}
- (CWCarousel *)posterView {
if (!_posterView) {
// 自定义布局
CWFlowLayout *flowLayout = [[CWFlowLayout alloc] initWithStyle:CWCarouselStyle_H_2];
flowLayout.itemWidth = kScreenWidth - 2*58;
flowLayout.itemSpace_H = 20;
_posterView = [[CWCarousel alloc] initWithFrame:CGRectZero
delegate:self
datasource:self
flowLayout:flowLayout];
_posterView.endless = YES;
_posterView.backgroundColor = DSClearColor;
_posterView.pageControl.hidden = YES;
[_posterView registerViewClass:[UICollectionViewCell class] identifier:@"PosterBarnnerCellID"];
}
return _posterView;
}
- (UIImageView *)bottomIV {
if (!_bottomIV) {
_bottomIV = [[UIImageView alloc] dk_initWithImagePicker:DKImagePickerWithNames(@"invite_basemap", @"dk_invite_basemap", @"dk_invite_basemap")];
}
return _bottomIV;
}
- (UIView *)inviteView {
if (!_inviteView) {
_inviteView = [UIView new];
_inviteView.dk_backgroundColorPicker = DKColorPickerWithKey(TabBarBG);
[_inviteView cornerRadius:12.0];
UIButton *shareLinkBtn = [self buildShareBtnWithTitle:@"复制链接" imgName:@"share_link" dkImgName:@"dk_share_link" shareType:ShareTypeLink];
UIButton *sharePosterBtn = [self buildShareBtnWithTitle:@"生成海报" imgName:@"share_poster" dkImgName:@"dk_share_poster" shareType:ShareTypePoster];
UIView *line = [UIView new];
line.dk_backgroundColorPicker = DKColorPickerWithColors(ColorFromHex(0xEEEEEE), DSWhite, DSWhite);
[_inviteView addSubview:line];
[shareLinkBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.bottom.equalTo(_inviteView);
}];
[sharePosterBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.right.bottom.equalTo(_inviteView);
make.width.equalTo(shareLinkBtn);
make.left.equalTo(shareLinkBtn.mas_right);
}];
[line mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_inviteView).offset(9);
make.bottom.equalTo(_inviteView).offset(-9);
make.centerX.equalTo(_inviteView);
make.width.equalTo(@1);
}];
}
return _inviteView;
}
- (UIButton *)buildShareBtnWithTitle:(NSString *)title imgName:(NSString *)imgName dkImgName:(NSString *)dkImgName shareType:(ShareType)shareType {
WS(weakSelf);
UIButton *shareBtn = [UIButton btnWithTitle:title font:SysFont(12.0)];
[shareBtn dk_setImage:DKImagePickerWithNames(imgName, dkImgName, imgName) forState:UIControlStateNormal];
[shareBtn dk_setTitleColorPicker:DKColorPickerWithColors(SubTitleColor, DkTitleColor, DSWhite) forState:UIControlStateNormal];
[shareBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 8, 0, 0)];
[shareBtn addTouchUpInsideHandler:^(NSInteger tag) {
if (weakSelf.shareDelegate && [weakSelf.shareDelegate respondsToSelector:@selector(shareWithType:item:)]) {
[weakSelf.shareDelegate shareWithType:shareType item:weakSelf.posterList[weakSelf.currentIndex]];
}
}];
[self.inviteView addSubview:shareBtn];
return shareBtn;
}
@end