YOUPAILZChatRoomEmojiAnimationWindow.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //
  2. // YOUPAILZChatRoomEmojiAnimationWindow.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/11/1.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZChatRoomEmojiAnimationWindow.h"
  9. #import "YOUPAILZChatRoomEmojiCell.h"
  10. #import "YOUPAIWZHorizontalPageFlowlayout.h"
  11. @interface YOUPAILZChatRoomEmojiAnimationWindow ()<UICollectionViewDelegate,UICollectionViewDataSource>
  12. @property (nonatomic,strong)NSArray <YOUPAILZChatRoomEmojiModel *>*youpaipdataSource;
  13. @property (nonatomic,strong)UICollectionView *youpaipcollectionView;
  14. @property (nonatomic,strong)UIPageControl *youpaippageView;
  15. @end
  16. @implementation YOUPAILZChatRoomEmojiAnimationWindow
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.baseView.hidden = YES;
  20. [self youpaifinitUI];
  21. [self youpaifrequestEmojiList];
  22. }
  23. - (void)youpaifinitUI{
  24. UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 243.0f + SafeHeight)];
  25. bgV.backgroundColor = HexColorFromRGB(0x2A2935);
  26. [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:bgV size:CGSizeMake(20.0f, 20.0f)];
  27. [self.view addSubview:bgV];
  28. [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.left.right.bottom.offset(0.0f);
  30. make.height.offset(243.0f + SafeHeight);
  31. }];
  32. UIView *footerV = [[UIView alloc] init];
  33. [bgV addSubview:footerV];
  34. [footerV mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.left.right.offset(0.0f);
  36. make.bottom.offset(-SafeHeight);
  37. make.height.offset(47.0f);
  38. }];
  39. UIButton *chatEmojiBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  40. [chatEmojiBtn setTitle:@"聊天表情" forState:UIControlStateNormal];
  41. [chatEmojiBtn setTitleColor:HexColorFromRGB(0x9F9DA5) forState:UIControlStateNormal];
  42. chatEmojiBtn.titleLabel.font = LCFont(12.0f);
  43. [chatEmojiBtn addTarget:self action:@selector(youpaifchatEmojiBtnClick) forControlEvents:UIControlEventTouchUpInside];
  44. [footerV addSubview:chatEmojiBtn];
  45. [chatEmojiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.left.offset(0.0f);
  47. make.centerY.equalTo(footerV.mas_centerY);
  48. make.size.mas_offset(CGSizeMake(84.0f, 33.0f));
  49. }];
  50. UIButton *animationEmojiBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  51. animationEmojiBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  52. [animationEmojiBtn setTitle:@"互动表情" forState:UIControlStateNormal];
  53. [animationEmojiBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  54. animationEmojiBtn.titleLabel.font = LCFont(12.0f);
  55. animationEmojiBtn.userInteractionEnabled = NO;
  56. [footerV addSubview:animationEmojiBtn];
  57. [animationEmojiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.left.equalTo(chatEmojiBtn.mas_right).offset(0.0f);
  59. make.centerY.equalTo(footerV.mas_centerY);
  60. make.size.mas_offset(CGSizeMake(84.0f, 33.0f));
  61. }];
  62. YOUPAIWZHorizontalPageFlowlayout *layout = [[YOUPAIWZHorizontalPageFlowlayout alloc] initWithRowCount:2 itemCountPerRow:4];
  63. layout.youpaiprowSpacing = 13.0f;
  64. layout.itemSize = CGSizeMake(77.0f, 77.0f);
  65. layout.youpaipedgeInsets = UIEdgeInsetsMake(14.0f, 0.0f, 14.0f, 0.0f);
  66. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  67. self.youpaipcollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, KScreenWidth, 243.0f-47.0f) collectionViewLayout:layout];
  68. self.youpaipcollectionView.backgroundColor = [UIColor clearColor];
  69. self.youpaipcollectionView.bounces = YES;
  70. self.youpaipcollectionView.pagingEnabled = YES;
  71. self.youpaipcollectionView.dataSource = self;
  72. self.youpaipcollectionView.delegate = self;
  73. self.youpaipcollectionView.showsHorizontalScrollIndicator=NO;
  74. self.youpaipcollectionView.showsVerticalScrollIndicator=NO;
  75. [self.youpaipcollectionView registerClass:[YOUPAILZChatRoomEmojiCell class] forCellWithReuseIdentifier:@"YOUPAILZChatRoomEmojiCell"];
  76. [bgV addSubview:self.youpaipcollectionView];
  77. UIPageControl *youpaippageView = [[UIPageControl alloc]initWithFrame:CGRectMake(0, self.youpaipcollectionView.mj_h - 8.0f, KScreenWidth, 8.0f)];
  78. youpaippageView.currentPageIndicatorTintColor = [UIColor whiteColor];
  79. youpaippageView.pageIndicatorTintColor = [[UIColor whiteColor] colorWithAlphaComponent:0.4f];;
  80. youpaippageView.userInteractionEnabled = NO;
  81. youpaippageView.hidesForSinglePage = YES;
  82. self.youpaippageView = youpaippageView;
  83. [bgV addSubview:youpaippageView];
  84. }
  85. - (void)youpaifchatEmojiBtnClick{
  86. [self dismissViewControllerAnimated:YES completion:^{
  87. if (self.youpaipyoupaifchatEmojiBtnClickBlock != nil) {
  88. self.youpaipyoupaifchatEmojiBtnClickBlock();
  89. }
  90. }];
  91. }
  92. #pragma mark - UICollectionViewDataSource
  93. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  94. return 1;
  95. }
  96. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  97. return self.youpaipdataSource.count;
  98. }
  99. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  100. {
  101. YOUPAILZChatRoomEmojiCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"YOUPAILZChatRoomEmojiCell" forIndexPath:indexPath];
  102. [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.item]];
  103. return cell;
  104. }
  105. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  106. YOUPAILZChatRoomEmojiModel *model = self.youpaipdataSource[indexPath.item];
  107. @weakify(self);
  108. [LCHttpHelper requestWithURLString:SendEmoji parameters:@{@"room_id":self.youpaipchatroomModel.youpaiproom_id,@"expression_id":model.youpaipid} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  109. @strongify(self);
  110. NSDictionary* dict = (NSDictionary*)responseObject;
  111. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  112. if (code == 0) {//成功
  113. [self dismissViewControllerAnimated:YES completion:^{}];
  114. }
  115. } failure:^(NSError *error) {
  116. }];
  117. }
  118. -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
  119. // 当前的索引
  120. NSInteger index = scrollView.contentOffset.x / self.youpaipcollectionView.mj_w;
  121. self.youpaippageView.currentPage = index;
  122. }
  123. - (void)youpaifrequestEmojiList{
  124. @weakify(self);
  125. [LCHttpHelper requestWithURLString:GetExpressionCate parameters:@{@"expression_type":@"sign"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  126. @strongify(self);
  127. NSDictionary* dict = (NSDictionary*)responseObject;
  128. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  129. if (code == 0) {//成功
  130. self.youpaipdataSource = [YOUPAILZChatRoomEmojiModel mj_objectArrayWithKeyValuesArray:[dict objectForKey:@"data"]];
  131. NSInteger totalRecord = self.youpaipdataSource.count;
  132. NSInteger maxResult = 8;
  133. NSInteger totalPage = (totalRecord + maxResult - 1) / maxResult;
  134. self.youpaippageView.numberOfPages = totalPage;
  135. self.youpaippageView.currentPage = 0;
  136. [self.youpaipcollectionView reloadData];
  137. }
  138. } failure:^(NSError *error) {
  139. }];
  140. }
  141. @end