YOUPAILZRecommendAnchorView.m 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. //
  2. // YOUPAILZRecommendAnchorView.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/6/11.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZRecommendAnchorView.h"
  9. #import "UIScrollView+LZRefresh.h"
  10. #import "YOUPAILZLiveListItemModel.h"
  11. #import "YOUPAILZRecommendAnchorCell.h"
  12. @interface YOUPAILZRecommendAnchorView ()<UITableViewDelegate,UITableViewDataSource>
  13. @property (nonatomic, weak) UIView *youpaipbgV;
  14. @property (nonatomic, weak) UIView *youpaiplistBgV;
  15. @property (nonatomic, weak) UITableView *youpaiptableView;
  16. @property (nonatomic, assign) NSInteger youpaippage;
  17. @property (nonatomic, strong)NSMutableArray <YOUPAILZLiveListItemModel *>*youpaipdataSource;
  18. @property (nonatomic, copy) void (^selectedItemBlcok)(YOUPAILZLiveListItemModel *model);
  19. @property (nonatomic, copy) void (^youpaiphiddenRecommendAnchorViewBlock)(void);
  20. @property (nonatomic, strong) NSString *youpaipcurrentLiveId;
  21. @end
  22. @implementation YOUPAILZRecommendAnchorView
  23. + (void)youpaifshowWithSuperView:(UIView *)superV currentLiveId:(NSString *)currentLiveId selectedBlock:(void (^)(YOUPAILZLiveListItemModel *model))selectedBlock hiddenBlock:(void (^)(void))hiddenBlcok{
  24. [[YOUPAILZRecommendAnchorView alloc] initWithFrame:superV.bounds superV:superV currentLiveId:currentLiveId selectedBlock:selectedBlock hiddenBlock:hiddenBlcok];
  25. }
  26. - (instancetype)initWithFrame:(CGRect)frame superV:(UIView *)superV currentLiveId:(NSString *)currentLiveId selectedBlock:(void (^)(YOUPAILZLiveListItemModel *model))selectedBlock hiddenBlock:(void (^)(void))hiddenBlcok{
  27. if (self = [super initWithFrame:frame]) {
  28. _youpaipcurrentLiveId = currentLiveId;
  29. _selectedItemBlcok = selectedBlock;
  30. _youpaiphiddenRecommendAnchorViewBlock = hiddenBlcok;
  31. [self youpaifinitUI];
  32. [superV addSubview:self];
  33. [self youpaifshowAnimation];
  34. [self youpaifrequestRecommendAnchorWithStatus:kRefreshHeader];
  35. }
  36. return self;
  37. }
  38. - (void)youpaifinitUI{
  39. UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(self.mj_w, 0, 137.0f + 28.0f, self.mj_h)];
  40. [self addSubview:bgV];
  41. self.youpaipbgV = bgV;
  42. UIView *youpaiplistBgV = [[UIView alloc] initWithFrame:CGRectMake(28.0f, 0.0f, 137.0f, self.mj_h)];
  43. youpaiplistBgV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6f];
  44. [bgV addSubview:youpaiplistBgV];
  45. self.youpaiplistBgV = youpaiplistBgV;
  46. UILabel *titleL = [[UILabel alloc] init];
  47. titleL.textColor = [UIColor whiteColor];
  48. titleL.font = LCFont12;
  49. titleL.text = @"猜你喜欢";
  50. [youpaiplistBgV addSubview:titleL];
  51. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.left.offset(8.0f);
  53. make.top.equalTo(StatusBarHeight + 15.0f);
  54. make.right.offset(-8.0f);
  55. }];
  56. UIImageView *imageV = [[UIImageView alloc] init];
  57. imageV.image = [UIImage imageNamed:@"vqu_images_L_live_recommend_anchor_left"];
  58. [self.youpaipbgV addSubview:imageV];
  59. [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.left.offset(0.0f);
  61. make.top.offset(StatusBarHeight + 24.0f);
  62. make.size.mas_equalTo(CGSizeMake(28.0f, 45.0f));
  63. }];
  64. UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  65. tableView.delegate = self;
  66. tableView.dataSource = self;
  67. tableView.rowHeight = 127.0f;
  68. tableView.estimatedSectionHeaderHeight = 0.0f;
  69. tableView.estimatedSectionFooterHeight = 0.0f;
  70. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  71. tableView.backgroundColor = [UIColor clearColor];
  72. tableView.showsVerticalScrollIndicator = NO;
  73. tableView.showsHorizontalScrollIndicator = NO;
  74. [youpaiplistBgV addSubview:tableView];
  75. self.youpaiptableView = tableView;
  76. __weak typeof(self) weakSelf = self;
  77. [tableView setRefreshHeaderWithBlock:^{
  78. [weakSelf youpaifrequestRecommendAnchorWithStatus:kRefreshHeader];
  79. }];
  80. [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  81. make.bottom.right.offset(0.0f);
  82. make.left.equalTo(imageV.mas_right);
  83. make.top.equalTo(titleL.mas_bottom).offset(5.0f);
  84. }];
  85. }
  86. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  87. return self.youpaipdataSource.count;
  88. }
  89. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  90. NSString *cellID = @"YOUPAILZRecommendAnchorCell";
  91. YOUPAILZRecommendAnchorCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  92. if (cell == nil) {
  93. cell = [[YOUPAILZRecommendAnchorCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  94. }
  95. [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.row]];
  96. return cell;
  97. }
  98. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  99. if(self.selectedItemBlcok){
  100. self.selectedItemBlcok(self.youpaipdataSource[indexPath.row]);
  101. [self youpaifhideAnimation];
  102. }
  103. }
  104. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  105. return CGFLOAT_MIN;
  106. }
  107. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  108. return CGFLOAT_MIN;
  109. }
  110. /// 设置加载更多
  111. - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{
  112. __weak typeof(self) weakSelf = self;
  113. [self.youpaiptableView setRefreshFooter:hidden withBlock:^{
  114. [weakSelf youpaifrequestRecommendAnchorWithStatus:kRefreshFooter];
  115. }];
  116. }
  117. /// 获取列表数据
  118. - (void)youpaifrequestRecommendAnchorWithStatus:(kRefreshStatus)status{
  119. if (status == kRefreshFooter) {
  120. self.youpaippage ++;
  121. }else{
  122. self.youpaippage = 1;
  123. }
  124. WeakSelf;
  125. [LCHttpHelper requestWithURLString:GetLeftLive parameters:@{@"page":@(self.youpaippage),@"current_live_id":self.youpaipcurrentLiveId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  126. [weakSelf.youpaiptableView endRefreshing:kRefreshAll];
  127. NSDictionary* dict = (NSDictionary*)responseObject;
  128. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  129. if (code == 0) {//成功
  130. if (status != kRefreshFooter) {
  131. [weakSelf.youpaipdataSource removeAllObjects];
  132. }
  133. NSDictionary *data = [dict objectForKey:@"data"];
  134. NSArray <YOUPAILZLiveListItemModel *>*list = [YOUPAILZLiveListItemModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"list"]];
  135. [weakSelf.youpaipdataSource addObjectsFromArray:list];
  136. [weakSelf.youpaiptableView reloadData];
  137. NSInteger youpaiptotalPage = [[data objectForKey:@"total_page"] integerValue];
  138. [weakSelf youpaifrefreshFooterWithHidden:weakSelf.youpaippage >= youpaiptotalPage];
  139. }
  140. } failure:^(NSError *error) {
  141. [weakSelf.youpaiptableView endRefreshing:kRefreshAll];
  142. }];
  143. }
  144. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  145. UITouch* touch = [touches anyObject];
  146. UIView* view = [touch view];
  147. if (view != self.youpaiplistBgV) {
  148. [self youpaifhideAnimation];
  149. }
  150. }
  151. - (void)youpaifshowAnimation{
  152. self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.0f];
  153. self.youpaipbgV.mj_x = self.mj_w;
  154. [UIView animateWithDuration:0.25f animations:^{
  155. self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.25f];
  156. self.youpaipbgV.mj_x = self.mj_w - 137.0f - 28.0f;
  157. }];
  158. }
  159. - (void)youpaifhideAnimation{
  160. self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.25f];
  161. self.youpaipbgV.mj_x = self.mj_w - 137.0f - 28.0f;
  162. [UIView animateWithDuration:0.25f animations:^{
  163. self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.0f];
  164. self.youpaipbgV.mj_x = self.mj_w;
  165. } completion:^(BOOL finished) {
  166. if (self.youpaiphiddenRecommendAnchorViewBlock) {
  167. self.youpaiphiddenRecommendAnchorViewBlock();
  168. }
  169. [self removeFromSuperview];
  170. }];
  171. }
  172. - (NSMutableArray <YOUPAILZLiveListItemModel *>*)youpaipdataSource{
  173. if (!_youpaipdataSource) {
  174. _youpaipdataSource = [NSMutableArray array];
  175. }
  176. return _youpaipdataSource;
  177. }
  178. @end