BogoPkAudienceView.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. //
  2. // BogoPkAudienceView.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2021/5/22.
  6. // Copyright © 2021 xfg. All rights reserved.
  7. //
  8. #import "BogoPkAudienceView.h"
  9. #import "BogoPKAudienceCell.h"
  10. @implementation BogoPkAudienceView
  11. - (instancetype)initWithFrame:(CGRect)frame
  12. {
  13. self = [super initWithFrame:frame];
  14. if (self) {
  15. [self setUpView];
  16. }
  17. return self;
  18. }
  19. -(void)setUpView{
  20. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  21. layout.itemSize = CGSizeMake(kRealValue(26), kRealValue(26));
  22. layout.sectionInset = UIEdgeInsetsMake(5, 15, 0, 10);
  23. layout.minimumInteritemSpacing = 15;
  24. layout.minimumLineSpacing = 10;
  25. self.leftCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(kRealValue(15), 0, kScreenW / 2, kRealValue(36)) collectionViewLayout:layout];
  26. self.leftCollectionView.delegate = self;
  27. self.leftCollectionView.dataSource = self;
  28. self.leftCollectionView.backgroundColor = kClearColor;
  29. [self.leftCollectionView registerNib:[UINib nibWithNibName:@"BogoPKAudienceCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"BogoPKAudienceCell"];
  30. self.rightCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(kScreenW / 2 + kRealValue(40), 0, kScreenW / 2, kRealValue(36)) collectionViewLayout:layout];
  31. self.rightCollectionView.backgroundColor = kClearColor;
  32. self.rightCollectionView.delegate = self;
  33. self.rightCollectionView.dataSource = self;
  34. [self.rightCollectionView registerNib:[UINib nibWithNibName:@"BogoPKAudienceCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"BogoPKAudienceCell"];
  35. [self addSubview:self.leftBGImgView];
  36. [self addSubview:self.rightBGImgView];
  37. [self addSubview:self.leftCollectionView];
  38. [self addSubview:self.rightCollectionView];
  39. [self.leftCollectionView addSubview:self.leftWinImg];
  40. [self.rightCollectionView addSubview:self.rightWinImg];
  41. [self addSubview:self.pkImgView];
  42. self.pkImgView.centerX = kScreenW / 2;
  43. self.pkImgView.centerY = self.leftCollectionView.centerY;
  44. }
  45. - (void)setModel:(BogoPkProgressModel *)model{
  46. self.leftArr = [NSMutableArray array];
  47. self.rightArr = [NSMutableArray array];
  48. if ([self.room_id isEqualToString:model.room_id1]) {
  49. [self.leftArr addObjectsFromArray:model.gift_list1];
  50. for (int i = 0; i < 3; i ++) {
  51. if (i + 1 > model.gift_list1.count) {
  52. BogoPkProgressGiftModel *model = [BogoPkProgressGiftModel new];
  53. [self.leftArr addObject:model];
  54. }
  55. if (i + 1 > model.gift_list2.count) {
  56. BogoPkProgressGiftModel *model = [BogoPkProgressGiftModel new];
  57. [self.rightArr addObject:model];
  58. }
  59. }
  60. //右边的数组要放在for循环的后面
  61. [self.rightArr addObjectsFromArray:model.gift_list2];
  62. }else{
  63. [self.leftArr addObjectsFromArray:model.gift_list2];
  64. for (int i = 0; i < 3; i ++) {
  65. if (i + 1 > model.gift_list2.count) {
  66. BogoPkProgressGiftModel *model = [BogoPkProgressGiftModel new];
  67. [self.leftArr addObject:model];
  68. }
  69. if (i + 1 > model.gift_list1.count) {
  70. BogoPkProgressGiftModel *model = [BogoPkProgressGiftModel new];
  71. [self.rightArr addObject:model];
  72. }
  73. }
  74. //右边的数组要放在for循环的后面
  75. [self.rightArr addObjectsFromArray:model.gift_list1];
  76. }
  77. [self.leftCollectionView reloadData];
  78. [self.rightCollectionView reloadData];
  79. }
  80. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  81. return 1;
  82. }
  83. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  84. return 3;
  85. }
  86. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  87. BogoPKAudienceCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BogoPKAudienceCell" forIndexPath:indexPath];
  88. UICollectionViewLayoutAttributes *attributes = [collectionView layoutAttributesForItemAtIndexPath:indexPath];
  89. if (collectionView == self.leftCollectionView) {
  90. BogoPkProgressGiftModel *model = self.leftArr[indexPath.row];
  91. if (indexPath.row == 0) {
  92. NSLog(@"indexPath.row == 0000%@",model.head_image);
  93. NSLog(@"self.leftArr[indexPath.row]%@",self.leftArr[indexPath.row]);
  94. [cell.imgView sd_setImageWithURL:[NSURL URLWithString:model.head_image] placeholderImage:[UIImage imageNamed:@"bogo_livePK_left_first"]];
  95. CGPoint cellCenter = attributes.center;
  96. CGPoint anchorPoint = [collectionView convertPoint:cellCenter toView:self];
  97. self.leftWinImg.centerX = anchorPoint.x - 10 - self.leftCollectionView.left;
  98. }else if (indexPath.row == 1){
  99. [cell.imgView sd_setImageWithURL:[NSURL URLWithString:model.head_image] placeholderImage:[UIImage imageNamed:@"bogo_livePK_left_second"]];
  100. }else if (indexPath.row == 2){
  101. [cell.imgView sd_setImageWithURL:[NSURL URLWithString:model.head_image] placeholderImage:[UIImage imageNamed:@"bogo_livePK_left_third"]];
  102. }
  103. if(model.id.length > 0)
  104. {
  105. [cell.imgView sd_setImageWithURL:[NSURL URLWithString:model.head_image] placeholderImage:[UIImage imageNamed:@"com_preload_head_img"]];
  106. }
  107. if (model.is_noble_mysterious.intValue == 1) {
  108. cell.imgView.image = kDefaultNobleMysteriousHeadImg;
  109. }
  110. }else{
  111. BogoPkProgressGiftModel *model = self.rightArr[indexPath.row];
  112. if (indexPath.row == 0) {
  113. [cell.imgView sd_setImageWithURL:[NSURL URLWithString:model.head_image] placeholderImage:[UIImage imageNamed:@"bogo_livePK_right_third"]];
  114. }else if (indexPath.row == 1){
  115. [cell.imgView sd_setImageWithURL:[NSURL URLWithString:model.head_image] placeholderImage:[UIImage imageNamed:@"bogo_livePK_right_second"]];
  116. }else if (indexPath.row == 2){
  117. CGPoint cellCenter = attributes.center;
  118. CGPoint anchorPoint = [collectionView convertPoint:cellCenter toView:self];
  119. self.rightWinImg.centerX = anchorPoint.x + 10 - self.rightCollectionView.left;
  120. [cell.imgView sd_setImageWithURL:[NSURL URLWithString:model.head_image] placeholderImage:[UIImage imageNamed:@"bogo_livePK_right_first"]];
  121. }
  122. if (model.is_noble_mysterious.intValue == 1) {
  123. cell.imgView.image = kDefaultNobleMysteriousHeadImg;
  124. }
  125. if(model.id.length > 0)
  126. {
  127. [cell.imgView sd_setImageWithURL:[NSURL URLWithString:model.head_image] placeholderImage:[UIImage imageNamed:@"com_preload_head_img"]];
  128. }
  129. }
  130. cell.contentView.backgroundColor = kClearColor;
  131. // bogo_livePK_left_first
  132. // bogo_livePK_left_normal
  133. return cell;
  134. }
  135. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  136. }
  137. -(UIImageView *)pkImgView{
  138. if (!_pkImgView) {
  139. _pkImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kRealValue(60), kRealValue(28))];
  140. _pkImgView.image = [UIImage imageNamed:@"bogo_livePK_center"];
  141. _pkImgView.centerX = kScreenW / 2;
  142. _pkImgView.centerY = kScreenH / 2;
  143. }
  144. return _pkImgView;
  145. }
  146. -(UIImageView *)leftBGImgView{
  147. if (!_leftBGImgView) {
  148. _leftBGImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenW / 2, self.height)];
  149. _leftBGImgView.image = [UIImage imageNamed:@"bogo_livePK_left_BGView"];
  150. }
  151. return _leftBGImgView;
  152. }
  153. -(UIImageView *)rightBGImgView{
  154. if (!_rightBGImgView) {
  155. _rightBGImgView = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenW / 2, 0, kScreenW / 2, self.height)];
  156. _rightBGImgView.image = [UIImage imageNamed:@"bogo_livePK_right_BGView"];
  157. }
  158. return _rightBGImgView;
  159. }
  160. -(UIImageView *)leftWinImg{
  161. if (!_leftWinImg) {
  162. _leftWinImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 16.8, 14.8)];
  163. _leftWinImg.image = [UIImage imageNamed:@"bogo_livePK_left_win"];
  164. }
  165. return _leftWinImg;
  166. }
  167. -(UIImageView *)rightWinImg{
  168. if (!_rightWinImg) {
  169. _rightWinImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 13.9, 11.2)];
  170. _rightWinImg.image = [UIImage imageNamed:@"bogo_livePK_right_win"];
  171. }
  172. return _rightWinImg;
  173. }
  174. @end