123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- //
- // YOUPAILZRecommendAnchorView.m
- // VQU
- //
- // Created by CY on 2021/6/11.
- // Copyright © 2021 leo. All rights reserved.
- //
- #import "YOUPAILZRecommendAnchorView.h"
- #import "UIScrollView+LZRefresh.h"
- #import "YOUPAILZLiveListItemModel.h"
- #import "YOUPAILZRecommendAnchorCell.h"
- @interface YOUPAILZRecommendAnchorView ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, weak) UIView *youpaipbgV;
- @property (nonatomic, weak) UIView *youpaiplistBgV;
- @property (nonatomic, weak) UITableView *youpaiptableView;
- @property (nonatomic, assign) NSInteger youpaippage;
- @property (nonatomic, strong)NSMutableArray <YOUPAILZLiveListItemModel *>*youpaipdataSource;
- @property (nonatomic, copy) void (^selectedItemBlcok)(YOUPAILZLiveListItemModel *model);
- @property (nonatomic, copy) void (^youpaiphiddenRecommendAnchorViewBlock)(void);
- @property (nonatomic, strong) NSString *youpaipcurrentLiveId;
- @end
- @implementation YOUPAILZRecommendAnchorView
- + (void)youpaifshowWithSuperView:(UIView *)superV currentLiveId:(NSString *)currentLiveId selectedBlock:(void (^)(YOUPAILZLiveListItemModel *model))selectedBlock hiddenBlock:(void (^)(void))hiddenBlcok{
- [[YOUPAILZRecommendAnchorView alloc] initWithFrame:superV.bounds superV:superV currentLiveId:currentLiveId selectedBlock:selectedBlock hiddenBlock:hiddenBlcok];
- }
- - (instancetype)initWithFrame:(CGRect)frame superV:(UIView *)superV currentLiveId:(NSString *)currentLiveId selectedBlock:(void (^)(YOUPAILZLiveListItemModel *model))selectedBlock hiddenBlock:(void (^)(void))hiddenBlcok{
- if (self = [super initWithFrame:frame]) {
- _youpaipcurrentLiveId = currentLiveId;
- _selectedItemBlcok = selectedBlock;
- _youpaiphiddenRecommendAnchorViewBlock = hiddenBlcok;
- [self youpaifinitUI];
- [superV addSubview:self];
- [self youpaifshowAnimation];
- [self youpaifrequestRecommendAnchorWithStatus:kRefreshHeader];
- }
- return self;
- }
- - (void)youpaifinitUI{
- UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(self.mj_w, 0, 137.0f + 28.0f, self.mj_h)];
- [self addSubview:bgV];
- self.youpaipbgV = bgV;
-
- UIView *youpaiplistBgV = [[UIView alloc] initWithFrame:CGRectMake(28.0f, 0.0f, 137.0f, self.mj_h)];
- youpaiplistBgV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6f];
- [bgV addSubview:youpaiplistBgV];
- self.youpaiplistBgV = youpaiplistBgV;
-
- UILabel *titleL = [[UILabel alloc] init];
- titleL.textColor = [UIColor whiteColor];
- titleL.font = LCFont12;
- titleL.text = @"猜你喜欢";
- [youpaiplistBgV addSubview:titleL];
- [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(8.0f);
- make.top.equalTo(StatusBarHeight + 15.0f);
- make.right.offset(-8.0f);
- }];
-
- UIImageView *imageV = [[UIImageView alloc] init];
- imageV.image = [UIImage imageNamed:@"vqu_images_L_live_recommend_anchor_left"];
- [self.youpaipbgV addSubview:imageV];
- [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(0.0f);
- make.top.offset(StatusBarHeight + 24.0f);
- make.size.mas_equalTo(CGSizeMake(28.0f, 45.0f));
- }];
-
- UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- tableView.delegate = self;
- tableView.dataSource = self;
- tableView.rowHeight = 127.0f;
- tableView.estimatedSectionHeaderHeight = 0.0f;
- tableView.estimatedSectionFooterHeight = 0.0f;
- tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- tableView.backgroundColor = [UIColor clearColor];
- tableView.showsVerticalScrollIndicator = NO;
- tableView.showsHorizontalScrollIndicator = NO;
- [youpaiplistBgV addSubview:tableView];
- self.youpaiptableView = tableView;
- __weak typeof(self) weakSelf = self;
- [tableView setRefreshHeaderWithBlock:^{
- [weakSelf youpaifrequestRecommendAnchorWithStatus:kRefreshHeader];
- }];
- [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.right.offset(0.0f);
- make.left.equalTo(imageV.mas_right);
- make.top.equalTo(titleL.mas_bottom).offset(5.0f);
- }];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return self.youpaipdataSource.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- NSString *cellID = @"YOUPAILZRecommendAnchorCell";
- YOUPAILZRecommendAnchorCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
- if (cell == nil) {
- cell = [[YOUPAILZRecommendAnchorCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
- }
- [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.row]];
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- if(self.selectedItemBlcok){
- self.selectedItemBlcok(self.youpaipdataSource[indexPath.row]);
- [self youpaifhideAnimation];
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- return CGFLOAT_MIN;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
- return CGFLOAT_MIN;
- }
- /// 设置加载更多
- - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{
- __weak typeof(self) weakSelf = self;
- [self.youpaiptableView setRefreshFooter:hidden withBlock:^{
- [weakSelf youpaifrequestRecommendAnchorWithStatus:kRefreshFooter];
- }];
- }
- /// 获取列表数据
- - (void)youpaifrequestRecommendAnchorWithStatus:(kRefreshStatus)status{
- if (status == kRefreshFooter) {
- self.youpaippage ++;
- }else{
- self.youpaippage = 1;
- }
- WeakSelf;
- [LCHttpHelper requestWithURLString:GetLeftLive parameters:@{@"page":@(self.youpaippage),@"current_live_id":self.youpaipcurrentLiveId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- [weakSelf.youpaiptableView endRefreshing:kRefreshAll];
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {//成功
- if (status != kRefreshFooter) {
- [weakSelf.youpaipdataSource removeAllObjects];
- }
- NSDictionary *data = [dict objectForKey:@"data"];
- NSArray <YOUPAILZLiveListItemModel *>*list = [YOUPAILZLiveListItemModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"list"]];
- [weakSelf.youpaipdataSource addObjectsFromArray:list];
- [weakSelf.youpaiptableView reloadData];
-
- NSInteger youpaiptotalPage = [[data objectForKey:@"total_page"] integerValue];
- [weakSelf youpaifrefreshFooterWithHidden:weakSelf.youpaippage >= youpaiptotalPage];
- }
- } failure:^(NSError *error) {
- [weakSelf.youpaiptableView endRefreshing:kRefreshAll];
- }];
- }
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
- UITouch* touch = [touches anyObject];
- UIView* view = [touch view];
- if (view != self.youpaiplistBgV) {
- [self youpaifhideAnimation];
- }
- }
- - (void)youpaifshowAnimation{
- self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.0f];
- self.youpaipbgV.mj_x = self.mj_w;
- [UIView animateWithDuration:0.25f animations:^{
- self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.25f];
- self.youpaipbgV.mj_x = self.mj_w - 137.0f - 28.0f;
- }];
- }
- - (void)youpaifhideAnimation{
- self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.25f];
- self.youpaipbgV.mj_x = self.mj_w - 137.0f - 28.0f;
- [UIView animateWithDuration:0.25f animations:^{
- self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.0f];
- self.youpaipbgV.mj_x = self.mj_w;
- } completion:^(BOOL finished) {
- if (self.youpaiphiddenRecommendAnchorViewBlock) {
- self.youpaiphiddenRecommendAnchorViewBlock();
- }
- [self removeFromSuperview];
- }];
- }
- - (NSMutableArray <YOUPAILZLiveListItemModel *>*)youpaipdataSource{
- if (!_youpaipdataSource) {
- _youpaipdataSource = [NSMutableArray array];
- }
- return _youpaipdataSource;
- }
- @end
|