GiftListView.m
9.15 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
//
// GiftListView.m
// LiveVideoCloud
//
// Created by 张旭 on 2017/3/14.
// Copyright © 2017年 cnlive. All rights reserved.
//
#import "GiftListView.h"
#import "GiftModel.h"
#import "LiveBaseView.h"
#import "AnimQueueManager.h"
#import "GiftPayButton.h"
#define MAX_LINE_COUNT 4
#define MAX_ROW_COUNT 2
#define GiftPayViewHeight 50
@interface GiftListView ()
@property (nonatomic ,strong) NSArray <GiftModel *>* _Nullable giftArray;
@property (nonatomic ,strong) NSArray <NSString *>* _Nullable images;
@property (nonatomic ,strong) NSArray <NSString *>* _Nullable giftNames;
@property (nonatomic ,strong) NSArray <NSString *>* _Nullable prices;
@property (nonatomic ,strong) NSArray <NSString *>* _Nullable types;
@property (nonatomic ,weak ) LiveBaseView * _Nullable liveBaseView;
@property (nonatomic, strong) AnimQueueManager * animQueueManager;
@property (nonatomic ,strong) GiftModel * _Nullable model;
@end
@implementation GiftListView
- (instancetype)initWithFrame:(CGRect)frame liveBaseView:(LiveBaseView *_Nullable)liveBaseView
{
if (self = [super initWithFrame:frame]) {
_images = [NSArray arrayWithObjects:@"porsch_small80",@"fighter_small80",@"plane_small80",@"love_gift",@"beer",@"chicken",@"cucumber",@"flower",@"hug",@"mouth",@"ring",@"rose",@"sticks",nil];
_giftNames = [NSArray arrayWithObjects:@"跑车",@"歼灭机",@"飞机",@"大大的爱心",@"啤酒",@"小鸡",@"小黄瓜",@"鲜花",@"抱抱",@"亲吻",@"戒指",@"玫瑰花",@"荧光棒",nil];
_prices = [NSArray arrayWithObjects:@"300000000",@"300000000",@"300000",@"30",@"30",@"3",@"3",@"1",@"3",@"1",@"3",@"30",@"300", nil];
_types = [NSArray arrayWithObjects:@"2",@"3",@"4",@"1",@"1",@"1",@"1",@"1",@"1",@"1",@"1",@"1",@"1", nil];
self.liveBaseView = liveBaseView;
self.animQueueManager = [AnimQueueManager sharedAnimQueueManager];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height - GiftPayViewHeight)];
scrollView.contentSize = CGSizeMake(self.width *(self.giftArray.count/(MAX_ROW_COUNT*MAX_LINE_COUNT) + 1), self.height - GiftPayViewHeight);
scrollView.pagingEnabled = YES;
scrollView.bounces = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.showsHorizontalScrollIndicator = NO;
[self addSubview:scrollView];
int line = 0;
int row = 0;
CGFloat giftX = 0;
CGFloat giftY = 0;
int page = 0;
for (int i = 0; i < self.giftArray.count; i ++) {
if (i % MAX_LINE_COUNT == 0 && i > 0) {
line ++;
}
if (i % (MAX_LINE_COUNT * MAX_ROW_COUNT) == 0 && i > 0) {
page++;
line = 0;
}
row = i % MAX_LINE_COUNT;
CGFloat giftWidth = self.width / MAX_LINE_COUNT * 1.0;
CGFloat giftHeight = (self.height - GiftPayViewHeight) / MAX_ROW_COUNT * 1.0;
giftX = row * giftWidth + page * scrollView.width;
giftY = line * giftHeight;
UIView *giftView = [self giftViewWithFrame:CGRectMake(giftX, giftY, giftWidth, giftHeight) model:self.giftArray[i]];
giftView.backgroundColor = [UIColor clearColor];
//礼物图片
UIImageView *picImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:self.giftArray[i].giftImageName]];
picImg.centerX = giftView.width * 0.5;
picImg.centerY = giftView.height * 0.5;
[giftView addSubview:picImg];
[scrollView addSubview:giftView];
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureClick:)];
giftView.tag = i + 10;
[giftView addGestureRecognizer:gesture];
}
UIImageView *giftBottomView = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.height - GiftPayViewHeight, self.width, GiftPayViewHeight)];
giftBottomView.image = [UIImage imageNamed:@"背景400x30"];
giftBottomView.alpha = 0.4;
[self addSubview:giftBottomView];
GiftPayButton *payBtn = [[GiftPayButton alloc] initWithFrame:CGRectMake(10, self.height - GiftPayViewHeight, 80, GiftPayViewHeight)];
[payBtn addTarget:self action:@selector(payClick) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:payBtn];
UIButton *sendBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.width - 70, self.height - GiftPayViewHeight + (GiftPayViewHeight - 30)*0.5, 60, 30)];
[sendBtn addTarget:self action:@selector(sendClick) forControlEvents:UIControlEventTouchUpInside];
[sendBtn setTitle:@"发送" forState:UIControlStateNormal];
[sendBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal
];
[sendBtn setBackgroundColor:[UIColor orangeColor]];
sendBtn.layer.cornerRadius = sendBtn.height * 0.5;
sendBtn.layer.masksToBounds = YES;
[self addSubview:sendBtn];
}
return self;
}
- (void)sendClick
{
NSLog(@"sendClick");
[Tools showNaviViewWithMessage:@"请先充值钻石哦"];
}
- (void)payClick
{
NSLog(@"payClick");
}
- (UIView *)giftViewWithFrame:(CGRect)frame model:(GiftModel *)model
{
_model = model;
UIView *giftView = [[UIView alloc] initWithFrame:frame];
if (model.giftStyle == GiftStyleCombo)
{//右上角连击标识
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(giftView.width - 17, 3, 15, 15)];
imageView.image = [UIImage imageNamed:@"continuous"];
[giftView addSubview:imageView];
}
//礼物价格lbl
UILabel *priceLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, giftView.height - 15, 40, 14)];
priceLbl.font = [UIFont systemFontOfSize:kDetailContentFont];
priceLbl.textColor = [UIColor greenColor];
priceLbl.text = model.price;
priceLbl.width = [priceLbl labelSize].width;
priceLbl.height = [priceLbl labelSize].height;
priceLbl.centerX = giftView.width * 0.5 - 4;
[giftView addSubview:priceLbl];
//礼物价格图标
UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"diamond"]];
image.left = priceLbl.right + 3;
image.centerY = priceLbl.centerY;
[giftView addSubview:image];
return giftView;
}
#pragma mark - 选择礼物点击
- (void)gestureClick:(UITapGestureRecognizer *)gesture
{
NSInteger tag = gesture.view.tag - 10;
NSLog(@"%zd",tag);
//右上角添加✔️,再次点击去掉✔️
GiftModel *model = self.giftArray[tag];
if (model.giftStyle == GiftStyleCombo) {
[self.animQueueManager addAnimationWithModel:self.giftArray[tag] animContentView:(UIView *)self.liveBaseView.presentView];
}else
{
[self.animQueueManager addAnimationWithModel:self.giftArray[tag] animContentView:self.liveBaseView];
}
}
- (NSString *)giftNameWithImageName:(NSString *)imageName
{
NSString *giftName = @"";
if ([_images containsObject:imageName]) {
NSInteger index = [_images indexOfObject:imageName];
giftName = [_giftNames objectAtIndex:index];
}
return giftName;
}
#pragma mark - getter
- (NSArray *)giftArray
{
if (!_giftArray)
{
NSArray *senders = [NSArray arrayWithObjects:@"张三",@"龙的传人",@"李四",@"王五",@"宋刘",@"老七",@"老八",@"老九",@"老十",@"老师",@"小十七",@"小十八",@"小十九", nil];
NSMutableArray *tempArr = [NSMutableArray array];
for (int i = 0; i < _images.count; i ++) {
NSString *type = _types[i];
if ([type isEqualToString:@"1"]) {
//combo
GiftModel *model1 = [GiftModel modelWithSender:senders[i] giftName:[self giftNameWithImageName:_images[i]] icon:@"love" giftImageName:_images[i]];
model1.giftStyle = GiftStyleCombo;
model1.price = _prices[i];
[tempArr addObject:model1];
}else
{//expen
GiftModel *model = [GiftModel modelWithSender:senders[i] giftName:[self giftNameWithImageName:_images[i]] icon:@"love" giftImageName:@""];
if ([type isEqualToString:@"2"]) {
model.giftStyle = GiftStylePorsch;
model.giftImageName = @"porsch_small80";
}
if ([type isEqualToString:@"3"]) {
model.giftStyle = GiftStyleFighter;
model.giftImageName = @"fighter_small80";
}
if ([type isEqualToString:@"4"]) {
model.giftStyle = GiftStylePlane;
model.giftImageName = @"plane_small80";
}
model.price = _prices[i];
[tempArr addObject:model];
}
}
_giftArray = [[NSArray alloc] initWithArray:tempArr];
}
return _giftArray;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end