LiveBaseView.m
29.5 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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
//
// LiveBaseView.m
// LiveVideoCloud
//
// Created by 张旭 on 2017/3/14.
// Copyright © 2017年 cnlive. All rights reserved.
//
#import "LiveBaseView.h"
#import "BottomToolView.h"
#import "GiftListView.h"
#import "GiftModel.h"
#import "PresentView.h"
#import "ComboCell.h"
#import "LVCAnimationManager.h"
#import "chatListCell.h"
#import "chatMsgModel.h"
#import "TopToolView.h"
#import "ChatBarrageManager.h"
#import "userInfoModel.h"
#import "PrivateView.h"
#import "ChatBarrageView.h"
#define BottomToolHeight 60
static NSString *chatType = @"type";
static NSString *chatMessage = @"message";
static NSString *msgGiftPrice = @"giftPrice";
static NSString *msgGiftName = @"giftName";
static NSString *msgGiftNumber = @"giftNumber";
static NSString *msgBarrage = @"messageBarrage";
static NSString *msgContent = @"content";
static NSString *giftType = @"giftType";
static NSString *chatRoomType = @"chatRoom";
static NSString *joinType = @"joinType";
typedef NS_ENUM(NSInteger, PopType) {//弹窗类型
PopTypeGift = 1,//礼物弹窗
PopTypeChat ,//聊天弹窗
PopTypePriMessage //私信弹窗
};
@interface LiveBaseView ()<bottomBtnDeledate,PresentViewDelegate,UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,userClickDelegate,CNLiveChatManagerDelegate,PopViewDelegate,GiftSelectDelegate>
@property (nonatomic ,strong ) UIScrollView * _Nullable scrollView;
//@property (nonatomic ,strong ,readwrite) AnimationBaseView * _Nullable animationBaseView;//展示层View
@property (nonatomic ,strong ) BottomToolView* _Nullable bottomToolView;
@property (nonatomic ,strong ) GiftListView * _Nullable giftListView;
@property (nonatomic ,weak ) UIView * _Nullable giftPopView;
@property (nonatomic ,strong ,readwrite) PresentView * _Nullable presentView;//连击View
@property (nonatomic ,assign ) PopType popType;
@property (nonatomic ,strong ) UITableView * _Nullable chatTableView;
@property (nonatomic ,strong ) NSMutableArray * _Nullable chatMsgArray;//聊天消息数组
@property (nonatomic ,strong ) TopToolView * _Nullable topToolsView;
@property (nonatomic ,strong ) UIView * _Nullable commentsView;
@property (nonatomic ,strong ) UITextField * _Nullable commentText;
@property (nonatomic ,assign ) CGFloat offsetHeight;
@property (nonatomic ,strong ) UISwitch * _Nullable barrageSwitch;
@property (nonatomic ,strong ) ChatBarrageManager * _Nullable chatManager;
@property (nonatomic ,strong ) ChatBarrageView * _Nullable barrageView;
@end
@implementation LiveBaseView
+ (instancetype _Nullable)liveBaseView
{
static LiveBaseView *liveBaseView;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
liveBaseView = [[LiveBaseView alloc] initWithFrame:SCREEN_RECT];
});
return liveBaseView;
}
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.clipsToBounds = YES;
[self addSubview:self.scrollView];
[self.scrollView addSubview:self.animationBaseView];
[self.animationBaseView addSubview:self.bottomToolView];
[self.animationBaseView addSubview:self.presentView];
[self addSubview:self.closeBtn];
[self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureClick:)]];
[[LVCAnimationManager shareManager] bubblingWithCenterPoint:CGPointMake(SCREEN_WIDTH - 50, SCREEN_HEIGHT - 50) toView:self.animationBaseView speed:1];
[self.animationBaseView addSubview:self.chatTableView];
[self.animationBaseView addSubview:self.topToolsView];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHidden:) name:UIKeyboardWillHideNotification object:nil];
}
return self;
}
- (void)setRoomId:(NSString *)roomId
{
_roomId = roomId;
[CNLiveChatManager sharedCNLiveChatManager].delegate = self;
[[CNLiveChatManager sharedCNLiveChatManager] joinChatRoom:roomId messageCount:10 success:^(NSString *targetId) {
NSLog(@"连接聊天室成功success %@",targetId);
} error:^(CNLiveChatErrorCode errors, NSString *targetId) {
NSLog(@"error");
}];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardWillShow:(NSNotification *)notify {
NSString *class = [[NSUserDefaults standardUserDefaults] objectForKey:keyboard];
if ([class isEqualToString:NSStringFromClass([self class])])
{
NSDictionary *userInfo = notify.userInfo;
CGRect newFrameKeyboard = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];//变化前的frame
[UIView animateWithDuration:0.25 animations:^{
self.animationBaseView.top = - newFrameKeyboard.size.height + self.bottomToolView.height;
}];
self.bottomToolView.hidden = YES;
}
}
- (void)keyboardWillHidden:(NSNotification *)notify {
NSString *class = [[NSUserDefaults standardUserDefaults] objectForKey:keyboard];
if ([class isEqualToString:NSStringFromClass([self class])])
{
[UIView animateWithDuration:0.1 animations:^{
self.animationBaseView.top = 0;
[self.animationBaseView setNeedsDisplay];
}];
self.bottomToolView.hidden = NO;
}
}
- (void)createCommentsView {
if (!_commentsView) {
_commentsView = [[UIView alloc] initWithFrame:CGRectMake(0.0, SCREEN_HEIGHT - 340.0, SCREEN_WIDTH, 40.0)];
_commentsView.backgroundColor = [UIColor clearColor];
UIImageView *bgView = [[UIImageView alloc] initWithFrame:_commentsView.bounds];
bgView.image = [[UIImage imageNamed:@"textInputBgColor"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0) resizingMode:UIImageResizingModeStretch];
bgView.alpha = 0.6;
bgView.userInteractionEnabled = YES;
[_commentsView addSubview:bgView];
[bgView addSubview:self.barrageSwitch];
UIButton *sendBtn = [[UIButton alloc] initWithFrame:CGRectMake(_commentsView.width - 80, 0, 80, _commentsView.height)];
[sendBtn addTarget:self action:@selector(sendClick) forControlEvents:UIControlEventTouchUpInside];
[sendBtn setTitle:@"发送" forState:UIControlStateNormal];
[sendBtn setTitleColor:[UIColor cyanColor] forState:UIControlStateNormal];
[bgView addSubview:sendBtn];
_commentText = [[UITextField alloc] initWithFrame:CGRectMake(_barrageSwitch.right + 20, 5, _commentsView.width - _barrageSwitch.right - 20 - 100, _commentsView.height - 10)];
// _commentText.layer.borderColor = [UIColor blueColor].CGColor;
// _commentText.layer.borderWidth = 1.0;
_commentText.layer.cornerRadius = 2.0;
_commentText.layer.masksToBounds = YES;
_commentText.inputAccessoryView = _commentsView;
_commentText.backgroundColor = [UIColor clearColor];
_commentText.returnKeyType = UIReturnKeySend;
_commentText.delegate = self;
_commentText.font = [UIFont systemFontOfSize:15.0];
_commentText.placeholder = @"和大家说点什么吧";
[bgView addSubview:_commentText];
}
UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[window addSubview:_commentsView];//添加到window上,在视图以外
[_commentText becomeFirstResponder];
}
- (void)showCommentText {
[self createCommentsView];
[_commentText becomeFirstResponder];//再次让textView成为第一响应者
}
#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (![textField.text isEqualToString:@""]) {
NSDictionary *dic;
if(self.barrageSwitch.isOn){
//开启横屏弹幕
dic = @{chatType:chatRoomType, chatMessage:@{msgBarrage:@"1",msgContent:textField.text}};
}else
{
dic = @{chatType:chatRoomType, chatMessage:@{msgBarrage:@"0",msgContent:textField.text}};
}
weakself
NSString *message = [Tools dictionaryToJson:dic];
[[CNLiveChatManager sharedCNLiveChatManager] sendMessage:message type:CNLive_ConversationType_CHATROOM targetId:_roomId success:^(CNLiveChatMessage *message) {
strongself
NSDictionary *JSONDic = [Tools dictionaryWithJsonString:message.messageContent];
NSDictionary *msg = [JSONDic objectForKey:chatMessage];
//将消息显示到列表中
chatMsgModel *model = [[chatMsgModel alloc] init];
model.name = message.userInfo.name;
model.content = [msg objectForKey:msgContent];
model.ID = message.targetId;
model.icon = message.userInfo.portraitUri;
model.cellWidth = self.chatTableView.width - 20;
model.uId = message.userInfo.userId;
[self.chatMsgArray addObject:model];
[self.chatTableView reloadData];
NSInteger section = [self.chatTableView numberOfSections];
if (section < 1) return;
NSInteger row = [self.chatTableView numberOfRowsInSection:section - 1];
if (row < 1) return;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row - 1 inSection:section - 1];
[self.chatTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
[self.chatTableView reloadData];
NSInteger isBarrage = [[[JSONDic objectForKey:chatMessage] objectForKey:msgBarrage] integerValue];
if (isBarrage) {//此条消息飘弹幕
chatMsgModel *barrageModel = [[chatMsgModel alloc] init];
barrageModel.name = message.userInfo.name;
barrageModel.content = [msg objectForKey:msgContent];
barrageModel.icon = message.userInfo.portraitUri;
[self.chatManager addAnimationWithModel:barrageModel animContentView:self.animationBaseView];
}
} error:^(CNLiveChatErrorCode errors, NSString *messageId, NSString *targetId) {
NSLog(@"%@",messageId);
}];
textField.text = @"";
}
[textField resignFirstResponder];
return YES;
}
- (void)bounceBtnType:(BounceBtnType)btnType model:(userInfoModel *_Nonnull)model
{
switch (btnType) {
case BounceBtnTypeAite:
{
[self bottomActionWithType:BtnClickTypeChat button:nil];
_commentText.text = [NSString stringWithFormat:@"@%@ ",model.name];
}
break;
case BounceBtnTypePriChat:
{
[self bottomActionWithType:BtnClickTypePriChat button:nil];
}
break;
case BounceBtnTypeHome:
{
}
break;
default:
break;
}
}
#pragma mark - bottomBtnActionDelegate
- (void)bottomActionWithType:(BtnClickType)btnType button:(UIButton *)button
{
[[LVCAnimationManager shareManager] suspend];
switch (btnType) {
case BtnClickTypeChat:
{
self.popType = PopTypeChat;
[[NSUserDefaults standardUserDefaults] setObject:NSStringFromClass([self class]) forKey:keyboard];
[[NSUserDefaults standardUserDefaults] synchronize];
[self showCommentText];
}
break;
case BtnClickTypePriChat:
{
self.popType = PopTypePriMessage;
[self hiddenView:YES];
[self showPrivateView];
[[NSUserDefaults standardUserDefaults] setObject:NSStringFromClass([PrivateView class]) forKey:keyboard];
[[NSUserDefaults standardUserDefaults] synchronize];
}
break;
case BtnClickTypeGift:
{
self.popType = PopTypeGift;
[self hiddenView:YES];
[self addSubview:self.giftListView];
self.giftListView.frame = CGRectMake(0, SCREEN_HEIGHT - 250, SCREEN_WIDTH, 250);
self.giftPopView = _giftListView;
}
break;
default:
break;
}
}
- (void)showPrivateView
{
PrivateView *privateView = [PrivateView privateView];
privateView.backgroundColor = [UIColor whiteColor];
[self addSubview:privateView];
privateView.delegate = self;
self.giftPopView = privateView;
[UIView animateWithDuration:0.5 animations:^{
privateView.top -= 300;
} completion:^(BOOL finished) {
}];
}
- (void)hiddenView:(BOOL)isHidden
{
self.bottomToolView.hidden = isHidden;
self.closeBtn.hidden = isHidden;
self.chatTableView.hidden = isHidden;
}
/**
清除当前pop的弹窗
*/
- (void)clearCurrentPopView
{
[[LVCAnimationManager shareManager] resume];
switch (self.popType) {
case PopTypeGift:
{
[UIView animateWithDuration:0.25 animations:^{
self.giftPopView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT);
[self hiddenView:NO];
} completion:^(BOOL finished) {
}];
}
break;
case PopTypeChat:
{
[self.commentText resignFirstResponder];
}
break;
case PopTypePriMessage:
{
if (((PrivateView *)self.giftPopView).isEditing) {
//正在编辑
[(PrivateView *)self.giftPopView endCurrentEditing];
}else//已结束编辑
{
[UIView animateWithDuration:0.25 animations:^{
self.giftPopView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 300);
[self hiddenView:NO];
} completion:^(BOOL finished) {
[self.giftPopView removeFromSuperview];
}];
}
}
break;
default:
break;
}
}
- (NSString *)giftModelToJSON:(GiftModel *)model
{
NSDictionary *dic = @{chatType:giftType,chatMessage:@{msgGiftName:model.giftName,msgGiftNumber:[NSString stringWithFormat:@"%zd",model.giftNumber],msgGiftPrice:model.price}};
return [Tools dictionaryToJson:dic];
}
#pragma mark - buttonClick触摸屏幕关闭方法
- (void)tapGestureClick:(UITapGestureRecognizer *)gesture
{
// NSLog(@" tap gesture%@",gesture.view);
[[LVCAnimationManager shareManager] bubblingWithCenterPoint:CGPointMake(SCREEN_WIDTH - 50, SCREEN_HEIGHT - 50) toView:self.animationBaseView];
[self clearCurrentPopView];
}
- (void)closeAction
{
switch (self.jumpType) {
case JumpControllerTypePresent:
{
[self.viewController dismissViewControllerAnimated:YES completion:nil];
}
break;
case JumpControllerTypePush:
{
[self.viewController.navigationController popViewControllerAnimated:YES];
}
break;
default:
break;
}
}
- (void)sendClick
{
[self textFieldShouldReturn:self.commentText];
}
- (void)barrageSiwthChange:(UISwitch *)barrageSwitch
{
if (barrageSwitch.isOn) {
_commentText.placeholder = @"1视讯币/条";
}else
{
_commentText.placeholder = @"和大家说点什么吧";
}
}
#pragma mark - userDetailDelegate聊天室列表个人信息
- (void)userClickWithModel:(chatMsgModel *)model
{
NSLog(@"点击人:%@",model.name);
userInfoModel *userModel = [[userInfoModel alloc ]init];
userModel.name = model.name;
userModel.icon = model.icon;
userModel.sign = model.content;//@"哈哈啊哈哈啊哈哈,这是我的签名~";
userModel.uId = @"123124";
[Tools showBouncedWithModel:userModel callBackBlock:^(UIView * _Nullable bounceView) {
NSLog(@"%@",bounceView);
}];
}
#pragma mark - PriClosePopViewDelegate
- (void)closeCurrentPopView
{
[self clearCurrentPopView];
}
#pragma mark - GiftSelectedDelegate
- (void)giftSelectedModel:(GiftModel *_Nonnull)model
{
if (![model.sender isEqualToString:@""]) {
if ([[CNLiveChatManager sharedCNLiveChatManager] getConnectionStatus] == CNLive_ConnectionStatus_Connected) {
weakself
[[CNLiveChatManager sharedCNLiveChatManager] sendMessage:[self giftModelToJSON:model] type:CNLive_ConversationType_CHATROOM targetId:_roomId success:^(CNLiveChatMessage *message) {
NSLog(@"send Msg success: %@",message.messageContent);
strongself
NSDictionary *JSONDic = [Tools dictionaryWithJsonString:message.messageContent];
NSDictionary *msgDic = [JSONDic objectForKey:chatMessage];
[self.giftListView addGiftAnimationWithModel:model];
CNLiveChatUserInfo *userInfo = message.userInfo;
//将消息显示到列表中
chatMsgModel *model1 = [[chatMsgModel alloc] init];
model1.name = message.userInfo.name;
model1.content = [NSString stringWithFormat:@" 送了一个 %@",msgDic[@"giftName"]];
model1.ID = message.targetId;
model1.icon = userInfo.portraitUri;
model1.cellWidth = self.chatTableView.width - 20;
model1.uId = userInfo.userId;
[self.chatMsgArray addObject:model1];
[self.chatTableView reloadData];
NSInteger section = [self.chatTableView numberOfSections];
if (section < 1) return;
NSInteger row = [self.chatTableView numberOfRowsInSection:section - 1];
if (row < 1) return;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row - 1 inSection:section - 1];
[self.chatTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
[self.chatTableView reloadData];
} error:^(CNLiveChatErrorCode errors, NSString *messageId, NSString *targetId) {
NSLog(@"error");
}];
}
}
}
#pragma mark - CNLiveChatManagerDelegate
/**
连接状态的的监听器
@param status 网络连接状态码
*/
- (void)onConnectionStatusChanged:(CNLiveConnectionStatus)status
{
NSLog(@"onConnectionStatusChanged");
}
/**
加入聊天室成功的监听
@param chatroomId 聊天室ID
*/
- (void)onChatRoomJoined:(NSString *)chatroomId
{
NSLog(@"onChatRoomJoined");
}
/*!
加入聊天室失败的监听
@param chatroomId 聊天室ID
@param errorCode 加入失败的错误码
@discussion 如果错误码是CNLive_KICKED_FROM_CHATROOM或CNLive_CHATROOM_NOT_EXIST,则不会自动重新加入聊天室,App需要按照自己的逻辑处理。
*/
- (void)onChatRoomJoinFailed:(NSString *)chatroomId
errorCode:(CNLiveChatErrorCode)errorCode
{
NSLog(@"onChatRoomJoinFailed");
}
/**
接收消息监听
@param message 消息实体类型对象(包括消息内容,消息ID,会话类型,目标ID,发送者的用户信息)
*/
- (void)onReceived:(CNLiveChatMessage *)message
{
// NSLog(@"onReceived");
switch (message.conversationType) {
case CNLive_ConversationType_CHATROOM:
{
NSDictionary *JSONDic = [Tools dictionaryWithJsonString:message.messageContent];
NSDictionary *msg = [JSONDic objectForKey:chatMessage];
//将消息显示到列表中
chatMsgModel *model = [[chatMsgModel alloc] init];
model.name = message.userInfo.name;
model.content = [msg objectForKey:msgContent];
model.ID = message.targetId;
model.icon = message.userInfo.portraitUri;
model.cellWidth = self.chatTableView.width - 20;
model.uId = message.userInfo.userId;
[self.chatMsgArray addObject:model];
[self.chatTableView reloadData];
NSInteger section = [self.chatTableView numberOfSections];
if (section < 1) return;
NSInteger row = [self.chatTableView numberOfRowsInSection:section - 1];
if (row < 1) return;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row - 1 inSection:section - 1];
[self.chatTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
[self.chatTableView reloadData];
NSInteger isBarrage = [[[JSONDic objectForKey:chatMessage] objectForKey:msgBarrage] integerValue];
if (isBarrage) {//此条消息飘弹幕
chatMsgModel *barrageModel = [[chatMsgModel alloc] init];
barrageModel.name = message.userInfo.name;
barrageModel.content = [msg objectForKey:msgContent];
barrageModel.icon = message.userInfo.portraitUri;
[self.chatManager addAnimationWithModel:barrageModel animContentView:self.animationBaseView];
}
}
break;
case CNLive_ConversationType_PRIVATE:
{
NSDictionary *JSONDic = [Tools dictionaryWithJsonString:message.messageContent];
NSDictionary *msg = [JSONDic objectForKey:chatMessage];
PrivateView *privateView = [PrivateView privateView];
//将消息显示到列表中
chatMsgModel *model = [[chatMsgModel alloc] init];
model.name = message.userInfo.name;
model.isMine = NO;
model.content = [msg objectForKey:msgContent];
model.ID = message.targetId;
model.icon = message.userInfo.portraitUri;
model.priCellWidth = privateView.tableView.width * 0.5 - 30;
[privateView.chatArray addObject:model];
[privateView.tableView reloadData];
NSInteger section = [privateView.tableView numberOfSections];
if (section < 1) return;
NSInteger row = [privateView.tableView numberOfRowsInSection:section - 1];
if (row < 1) return;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row - 1 inSection:section - 1];
[privateView.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
[privateView.tableView reloadData];
}
break;
default:
break;
}
}
/**
当前用户在其他设备上登录,此设备被踢下线。
*/
- (void)kickedByAnotherDevice
{
NSLog(@"kickedByAnotherDevice");
}
#pragma mark - 聊天消息列表
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.chatMsgArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
chatListCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([chatListCell class]) forIndexPath:indexPath];
cell.delegate = self;
[cell loadUIWithModel:self.chatMsgArray[indexPath.row]];
return cell;
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [self.chatMsgArray[indexPath.row] cellHeight];
}
#pragma mark - PresentViewDelegate
- (PresentViewCell *)presentView:(PresentView *)presentView cellOfRow:(NSInteger)row
{
return [[ComboCell alloc] initWithRow:row];
}
- (void)presentView:(PresentView *)presentView configCell:(PresentViewCell *)cell model:(id<PresentModelAble>)model
{
ComboCell *comboCell = (ComboCell *)cell;
comboCell.model = (GiftModel *)model;
}
- (void)presentView:(PresentView *)presentView didSelectedCellOfRowAtIndex:(NSUInteger)index
{
ComboCell *cell = [presentView cellForRowAtIndex:index];
NSLog(@"你点击了:%@", cell.model.giftName);
}
- (void)presentView:(PresentView *)presentView animationCompleted:(NSInteger)shakeNumber model:(id<PresentModelAble>)model
{
NSLog(@"%@礼物的连送动画执行完成", model.giftName);
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
[self clearCurrentPopView];
}
#pragma mark - setter
-(void)setViewController:(UIViewController *)viewController
{
_viewController = viewController;
}
#pragma mark - getter
- (UIScrollView *)scrollView
{
if (!_scrollView)
{
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
_scrollView.contentSize = CGSizeMake(SCREEN_WIDTH*2, SCREEN_HEIGHT);
_scrollView.contentOffset = CGPointMake(SCREEN_WIDTH, 0);
_scrollView.bounces = NO;
_scrollView.pagingEnabled = YES;
_scrollView.showsVerticalScrollIndicator = NO;
_scrollView.showsHorizontalScrollIndicator = NO;
_scrollView.backgroundColor = [UIColor clearColor];
_scrollView.delegate = self;
}
return _scrollView;
}
- (AnimationBaseView *)animationBaseView
{
if (!_animationBaseView)
{
_animationBaseView = [[AnimationBaseView alloc] initWithFrame:CGRectMake(self.scrollView.width, 0, self.scrollView.width, self.scrollView.height)];
}
return _animationBaseView;
}
- (PresentView *)presentView
{
if (!_presentView)
{
_presentView = [[PresentView alloc] initWithFrame:CGRectMake(0, 200, 220, 200)];
_presentView.delegate = self;
_presentView.backgroundColor = [UIColor clearColor];
}
return _presentView;
}
- (UISwitch *)barrageSwitch
{
if (!_barrageSwitch)
{
_barrageSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(10, 10, 40, 30)];
_barrageSwitch.tintColor = [UIColor greenColor];
_barrageSwitch.onTintColor = [UIColor greenColor];
_barrageSwitch.thumbTintColor = [UIColor whiteColor];
_barrageSwitch.centerY = _commentsView.height * 0.5;
[_barrageSwitch addTarget:self action:@selector(barrageSiwthChange:) forControlEvents:UIControlEventValueChanged];
}
return _barrageSwitch;
}
- (BottomToolView *)bottomToolView
{
if (!_bottomToolView)
{
_bottomToolView = [[BottomToolView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - BottomToolHeight, SCREEN_WIDTH, BottomToolHeight)];
_bottomToolView.delegate = self;
}
return _bottomToolView;
}
- (TopToolView *)topToolsView
{
if (!_topToolsView)
{
_topToolsView = [[TopToolView alloc] initWithFrame:CGRectMake(10, 20, 100, 30) isHost:NO];
}
return _topToolsView;
}
- (UITableView *)chatTableView
{
if (!_chatTableView) {
UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(10, SCREEN_HEIGHT - 150 - BottomToolHeight - 10, 300, 150)];
tableView.delegate = self;
tableView.dataSource = self;
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[tableView registerClass:[chatListCell class] forCellReuseIdentifier:NSStringFromClass([chatListCell class])];
tableView.showsVerticalScrollIndicator = NO;
tableView.showsHorizontalScrollIndicator = NO;
tableView.bounces = NO;
tableView.backgroundColor = [UIColor clearColor];
// UIView *view = [[UIView alloc] initWithFrame:tableView.bounds];
// [tableView addSubview:view];
//
// UIImageView *bgView = [[UIImageView alloc] initWithFrame:view.bounds];
// bgView.image = [UIImage imageNamed:@"背景400x300"];
// [view addSubview:bgView];
// tableView.backgroundView = view;
_chatTableView = tableView;
}
return _chatTableView;
}
- (NSMutableArray *)chatMsgArray
{
if (!_chatMsgArray) {
_chatMsgArray = [NSMutableArray array];
}
return _chatMsgArray;
}
- (UIButton *)closeBtn
{
if (!_closeBtn)
{
UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
closeBtn.frame = CGRectMake(SCREEN_WIDTH - 43,SCREEN_HEIGHT - self.bottomToolView.height + (self.bottomToolView.height - 45)*0.5, 45, 45);
[closeBtn setBackgroundImage:[UIImage imageNamed:@"LiveCloseNormal"] forState:UIControlStateNormal];
[closeBtn setBackgroundImage:[UIImage imageNamed:@"LiveCloseTouch"] forState:UIControlStateHighlighted];
_closeBtn = closeBtn;
}
return _closeBtn;
}
- (GiftListView *)giftListView
{
if (!_giftListView)
{
_giftListView = [[GiftListView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 250, SCREEN_WIDTH, 250) liveBaseView:self];
_giftListView.delegate = self;
UIImageView *giftBg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _giftListView.width, _giftListView.height)];
giftBg.image = [UIImage imageNamed:@"背景400x300"];
giftBg.centerX = _giftListView.width * 0.5;
giftBg.centerY = _giftListView.height * 0.5;
giftBg.alpha = 0.4;
[_giftListView addSubview:giftBg];
}
return _giftListView;
}
- (ChatBarrageManager *)chatManager
{
if (!_chatManager)
{
_chatManager = [ChatBarrageManager sharedManager];
}
return _chatManager;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end