IVTMeMineUserView.m
16 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
//
// IVTMeMineUserView.m
// IVTMeLive
//
// Created by XRG on 16/5/11.
// Copyright © 2016年 Joky. All rights reserved.
//
#import "IVTMeMineUserView.h"
#import "Masonry.h"
#import "UIColor+IVTMeColor.h"
#import "UIFont+IVTMeFont.h"
#import "AppDelegate.h"
#import "IVTKSYLiveShowViewController.h"
static IVTMeMineUserView *instance = nil;
@interface IVTMeMineUserView()
{
UIImageView *bgImageView;
UIButton *close;
UIImageView *backGround;
UIImageView *userIcon;
UILabel *name;
UIImageView *sex;
UIImageView *grade;
UILabel *lelveNum;
UILabel *signatureLabel;
UIImageView *devote;//贡献最多
UIView* lineView_H1;
UIView* lineView_H2;
UILabel *fansNum;//粉丝数
UILabel *attentionNum;//关注
UILabel *giftNum;//送出礼物
UILabel *miTang;//蜜糖数
}
@end
@implementation IVTMeMineUserView
#pragma mark - 初始化视图 CGRectMake((kScreenWidth - 280)/2, (kScreenHeight - 240)/2, 280, 240)
+ (IVTMeMineUserView *)sharedInstance{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[self alloc] init];
[instance setupSubViews];
});
return instance;
}
+ (instancetype)allocWithZone:(struct _NSZone *)zone{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [super allocWithZone:zone];
});
return instance;
}
- (void)setupSubViews{
self.frame = [[UIScreen mainScreen] bounds];
/**
* 背景灰色
*/
bgImageView = [[UIImageView alloc]init];
bgImageView.frame = self.bounds;
bgImageView.backgroundColor = [UIColor blackColor];
bgImageView.alpha = 0.7f;
bgImageView.userInteractionEnabled = YES;
[self addSubview:bgImageView];
backGround = [[UIImageView alloc]initWithFrame:CGRectMake(30, (kScreenHeight - 250)/2, kScreenWidth - 60, 250)];
backGround.image = [UIImage imageNamed:@"用户详情框--背景"];
backGround.userInteractionEnabled = YES;
[self addSubview:backGround];
userIcon = [[UIImageView alloc]init];
userIcon.image = [UIImage imageNamed:@"用户详情--头像"];
userIcon.clipsToBounds = YES;
userIcon.layer.cornerRadius = 70/2;
[backGround addSubview:userIcon];
[userIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(70, 70));
make.centerX.equalTo(backGround);
make.top.equalTo(backGround.mas_top).with.offset(-15);
}];
close =[UIButton new];
[close setImage:[UIImage imageNamed:@"用户详情--关闭"] forState:UIControlStateNormal];
close.enabled =YES;
[close addTarget:self action:@selector(hidden) forControlEvents:UIControlEventTouchUpInside];
[backGround addSubview:close];
[close mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(backGround.mas_top).with.offset(12);
make.right.equalTo(backGround.mas_right).with.offset(-15);
make.size.mas_equalTo(CGSizeMake(40, 40));
}];
name = [[UILabel alloc]init];
name.backgroundColor = [UIColor clearColor];
name.textColor = [UIColor IVTMainTextColor];
name.font = [UIFont YXBoldFontOfSize:15];
name.textAlignment = NSTextAlignmentLeft;
[backGround addSubview:name];
// [name mas_makeConstraints:^(MASConstraintMaker *make) {
// make.top.equalTo(userIcon.mas_bottom).with.offset(14);
// make.centerX.equalTo(backGround).with.offset(-10);
// make.size.mas_equalTo(CGSizeMake(100, 18));
// }];
sex = [[UIImageView alloc]init];
sex.image = [UIImage imageNamed:@"用户详情--性别-女"];
[backGround addSubview:sex];
// [sex mas_makeConstraints:^(MASConstraintMaker *make) {
// make.top.equalTo(userIcon.mas_bottom).with.offset(14);
// make.left.equalTo(name.mas_right).with.offset(4);
// make.size.mas_equalTo(CGSizeMake(12, 15));
//
// }];
grade = [[UIImageView alloc]init];
grade.image = [UIImage imageNamed:@"等级蓝色"];
[backGround addSubview:grade];
grade.userInteractionEnabled = YES;
// [grade mas_makeConstraints:^(MASConstraintMaker *make) {
// make.top.equalTo(userIcon.mas_bottom).with.offset(14);
// make.left.equalTo(sex.mas_right).with.offset(4);
// make.size.mas_equalTo(CGSizeMake(28, 14));
// }];
lelveNum =[[UILabel alloc]init];
lelveNum.textColor = [UIColor whiteColor];
lelveNum.font = [UIFont YXFontOfSize:10];
[grade addSubview:lelveNum];
[lelveNum mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(grade.mas_left).offset(14);
make.top.equalTo(grade.mas_top).offset(3);
make.size.mas_equalTo(CGSizeMake(14, 8));
}];
signatureLabel = [[UILabel alloc]init];
[backGround addSubview:signatureLabel];
signatureLabel.backgroundColor = [UIColor clearColor];
signatureLabel.textColor = [UIColor IVTMainTextColor];
signatureLabel.alpha = 0.7f;
signatureLabel.font = [UIFont YXFontOfSize:15];
signatureLabel.textAlignment = NSTextAlignmentCenter;
[signatureLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(name.mas_bottom).offset(5);
make.left.equalTo(backGround.mas_left);
make.right.equalTo(backGround.mas_right);
make.height.mas_equalTo(15);
}];
devote = [[UIImageView alloc]init];
devote.layer.cornerRadius = 45 / 2;
devote.clipsToBounds = YES;
[backGround addSubview:devote];
[devote mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(signatureLabel.mas_bottom).with.offset(8);
make.centerX.equalTo(backGround);
make.size.mas_equalTo(CGSizeMake(45, 45));
}];
//线
lineView_H1 = [[UIView alloc] init];
lineView_H1.backgroundColor = [UIColor YXColorWithHexCode:@"#dcdcdc"];
[backGround addSubview:lineView_H1];
[lineView_H1 mas_makeConstraints:^(MASConstraintMaker* make) {
make.top.equalTo(devote.mas_bottom).with.offset(15);
make.left.equalTo(backGround.mas_left);
make.right.equalTo(backGround.mas_right);
make.height.equalTo(@0.5);
}];
CGFloat widthForLabel = (kScreenWidth - 60)/4;
fansNum = [[UILabel alloc]init];
[backGround addSubview:fansNum];
fansNum.text = @"4212";
fansNum.textAlignment = NSTextAlignmentCenter;
fansNum.font = [UIFont YXFontOfSize:13];
fansNum.textColor = [UIColor YXColorWithHexCode:@"#A0A0A0"];
[fansNum mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(lineView_H1.mas_bottom).with.offset(20);
make.left.equalTo(backGround.mas_left).with.offset(0);
make.size.mas_equalTo(CGSizeMake(widthForLabel, 15));
}];
UILabel *fansNameLabel = [[UILabel alloc]init];
fansNameLabel.text = @"粉丝";
fansNameLabel.textAlignment = NSTextAlignmentCenter;
fansNameLabel.font = [UIFont YXFontOfSize:13];
fansNameLabel.textColor = [UIColor YXColorWithHexCode:@"#A0A0A0"];
[backGround addSubview:fansNameLabel];
[fansNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(fansNum.mas_bottom).offset(5);
make.left.equalTo(fansNum.mas_left);
make.size.mas_equalTo(CGSizeMake(widthForLabel, 15));
}];
attentionNum = [[UILabel alloc]init];
[backGround addSubview:attentionNum];
attentionNum.textAlignment = NSTextAlignmentCenter;
attentionNum.text = @"7.4万";
attentionNum.font = [UIFont YXFontOfSize:13];
attentionNum.textColor = [UIColor YXColorWithHexCode:@"#A0A0A0"];
[attentionNum mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(lineView_H1.mas_bottom).with.offset(20);
make.left.equalTo(fansNum.mas_right).with.offset(0);
make.size.mas_equalTo(CGSizeMake(widthForLabel, 15));
}];
UILabel *attentionNameLabel = [[UILabel alloc]init];
attentionNameLabel.text = @"关注";
attentionNameLabel.textAlignment = NSTextAlignmentCenter;
attentionNameLabel.font = [UIFont YXFontOfSize:13];
attentionNameLabel.textColor = [UIColor YXColorWithHexCode:@"#A0A0A0"];
[backGround addSubview:attentionNameLabel];
[attentionNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(attentionNum.mas_bottom).offset(5);
make.left.equalTo(attentionNum.mas_left);
make.size.mas_equalTo(CGSizeMake(widthForLabel, 15));
}];
giftNum = [[UILabel alloc]init];
[backGround addSubview:giftNum];
giftNum.textAlignment = NSTextAlignmentCenter;
giftNum.text = @"42";
giftNum.font = [UIFont YXFontOfSize:13];
giftNum.textColor = [UIColor YXColorWithHexCode:@"#A0A0A0"];
[giftNum mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(lineView_H1.mas_bottom).with.offset(20);
make.left.equalTo(attentionNum.mas_right);
make.size.mas_equalTo(CGSizeMake(widthForLabel, 15));
}];
UILabel *giftNameLabel = [[UILabel alloc]init];
giftNameLabel.text = @"送出";
giftNameLabel.textAlignment = NSTextAlignmentCenter;
giftNameLabel.font = [UIFont YXFontOfSize:13];
giftNameLabel.textColor = [UIColor YXColorWithHexCode:@"#A0A0A0"];
[backGround addSubview:giftNameLabel];
[giftNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(giftNum.mas_bottom).offset(5);
make.left.equalTo(giftNum.mas_left);
make.size.mas_equalTo(CGSizeMake(widthForLabel, 15));
}];
miTang = [[UILabel alloc]init];
[backGround addSubview:miTang];
miTang.textAlignment = NSTextAlignmentCenter;
miTang.text = @"745";
miTang.font = [UIFont YXFontOfSize:13];
miTang.textColor = [UIColor YXColorWithHexCode:@"#A0A0A0"];
[miTang mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(lineView_H1.mas_bottom).with.offset(20);
make.left.equalTo(giftNum.mas_right);
make.size.mas_equalTo(CGSizeMake(widthForLabel, 15));
}];
UILabel *miTangNameLabel = [[UILabel alloc]init];
miTangNameLabel.text = @"蜜糖";
miTangNameLabel.textAlignment = NSTextAlignmentCenter;
miTangNameLabel.font = [UIFont YXFontOfSize:13];
miTangNameLabel.textColor = [UIColor YXColorWithHexCode:@"#A0A0A0"];
[backGround addSubview:miTangNameLabel];
[miTangNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(miTang.mas_bottom).offset(5);
make.left.equalTo(miTang.mas_left);
make.size.mas_equalTo(CGSizeMake(widthForLabel, 15));
}];
// //下面的线
// lineView_H2 = [[UIView alloc] init];
// lineView_H2.backgroundColor = [UIColor YXColorWithHexCode:@"#dcdcdc"];
// [backGround addSubview:lineView_H2];
// [lineView_H2 mas_makeConstraints:^(MASConstraintMaker* make) {
// make.top.equalTo(miTang.mas_bottom).with.offset(24);
// make.left.equalTo(backGround.mas_left);
// make.right.equalTo(backGround.mas_right);
// make.height.equalTo(@0.5);
// }];
}
- (void)setEntity:(NSDictionary *)entity{
_entity = entity;
NSString *avatar =[NSString stringWithFormat:@"%@",[_entity objectForKey:@"avatar"]];
if ([avatar isEqualToString:@"http://api.me.cnlive.com/avatar.png"]) {
userIcon.image = [UIImage imageNamed:@"用户详情--用户--占位头像"];
}else{
[userIcon sd_setImageWithURL:[NSURL URLWithString:avatar] placeholderImage:[UIImage imageNamed:@"占位头像"]];
}
NSString *nameString = [[_entity objectForKey:@"name"] base64DecodedToString];
name.text = nameString;
[name mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(userIcon.mas_bottom).with.offset(14);
make.centerX.equalTo(backGround.mas_centerX).offset(-27);
// make.size.mas_equalTo(CGSizeMake([IVTMeLabel widthOfLabelWithString:nameString sizeOfFont:17 height:15], 15));
}];
[sex mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(userIcon.mas_bottom).with.offset(14);
make.left.equalTo(name.mas_right).with.offset(5);
make.size.mas_equalTo(CGSizeMake(12, 15));
}];
[grade mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(userIcon.mas_bottom).with.offset(14);
make.left.equalTo(sex.mas_right).with.offset(4);
make.size.mas_equalTo(CGSizeMake(28, 14));
}];
NSString *sexString = [_entity objectForKey:@"sex"];
if ([sexString isEqualToString:@"male"]) {
[sex setImage:[UIImage imageNamed:@"性别男"]];
}else if ([sexString isEqualToString:@"female"]){
[sex setImage:[UIImage imageNamed:@"性别女"]];
} else {
[sex setImage:[UIImage imageNamed:@"性别女"]];
}
if ([_entity valueForKey:@"signature"] != nil) {
signatureLabel.text = [NSString stringWithFormat:@"%@",[[_entity valueForKey:@"signature"] base64DecodedToString]];
}else{
signatureLabel.text = @"我很懒,所以什么都没有写";
}
NSString *level = [_entity objectForKey:@"level"];
lelveNum.text = level;
grade.image = [IVTAccountTool showLevel:level].image;
NSString *firstavatar =[NSString stringWithFormat:@"%@",[_entity objectForKey:@"firstavatar"]];
if ([firstavatar isEqualToString:@"http://api.me.cnlive.com/avatar.png"]) {
devote.image = [UIImage imageNamed:@"用户详情--用户--占位头像"];
}else{
[devote sd_setImageWithURL:[NSURL URLWithString:firstavatar] placeholderImage:[UIImage imageNamed:@"占位头像"]];
}
NSInteger followercount = [[_entity objectForKey:@"followercount"] integerValue];
NSString *followCount = [IVTAccountTool numberFormat:followercount];
NSInteger fanscount = [[_entity objectForKey:@"fanscount"] integerValue];
NSString *fanCount = [IVTAccountTool numberFormat:fanscount];
attentionNum.text =followCount;
fansNum.text = fanCount;
NSInteger sentgiftmoneycount = [[_entity objectForKey:@"sentgiftmoneycount"] integerValue]/ 100;
NSString *giftNumString = [IVTAccountTool numberFormat:sentgiftmoneycount];
giftNum.text = giftNumString;
NSInteger miTangNumber = [[_entity objectForKey:@"mecointotal"] integerValue];
NSString *mitangNum = [IVTAccountTool numberFormat:miTangNumber];
miTang.text =mitangNum;
}
-(void)hidden{
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
animation.duration = 0.4;
NSMutableArray *values = [NSMutableArray array];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
animation.values = values;
[backGround.layer addAnimation:animation forKey:@"scale"];
[UIView animateWithDuration:0.5 animations:^{
bgImageView.alpha = 0;
} completion:^(BOOL finished){
}];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self removeFromSuperview];
});
}
- (void)show{
[((AppDelegate *)[[UIApplication sharedApplication] delegate]).window addSubview:self];//添加分享视图
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
animation.duration = 0.4f;
NSMutableArray *values = [NSMutableArray array];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
animation.values = values;
[backGround.layer addAnimation:animation forKey:@"scale"];
[UIView animateWithDuration:0.5 animations:^{
bgImageView.alpha = 0.7f;
} completion:^(BOOL finished){
}];}
@end