// // RQVideoDetailSubPageViewController.m // SDJK // // Created by 张嵘 on 2021/10/26. // 视频详情的视频列表子页面 #import "RQVideoDetailSubPageViewController.h" @interface RQVideoDetailSubPageViewController () /// viewModel @property (nonatomic, readonly, strong) RQVideoDetailSubPageViewModel *viewModel; @property (nonatomic, readwrite, copy) void(^scrollCallback)(UIScrollView *scrollView); @property (nonatomic, readwrite, strong) RQVideoDetailSubPageSectionHeaderView *videoDetailSubPageSectionHeaderView; @property (nonatomic, readwrite, strong) UIView *tableViewBgView; /// 顶部视频播放器的高度 @property (nonatomic, readonly, assign) float videoPlayerHeight; /// 顶部超出背景的高度 @property (nonatomic, readonly, assign) float coverBgViewHeight; /// 顶部sectionHeaderView的高度 @property (nonatomic, readonly, assign) float sectionHeaderViewHeight; /// 底部分类筛选栏的高度 @property (nonatomic, readonly, assign) float categoryViewHeight; @end @implementation RQVideoDetailSubPageViewController @dynamic viewModel, tableView; #pragma mark - SystemMethod - (void)viewDidLoad { [super viewDidLoad]; /// 初始化 [self rq_setup]; } - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; self.tableView.frame = CGRectMake(0, self.sectionHeaderViewHeight, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT - RQ_APPLICATION_STATUS_BAR_HEIGHT - self.videoPlayerHeight - self.categoryViewHeight - 20 - self.sectionHeaderViewHeight - 16); self.tableViewBgView.frame = CGRectMake(16, ((self.videoDetailSubPageSectionHeaderView.headerBtn.height / 2.f) + 22), RQ_SCREEN_WIDTH - 32, RQ_SCREEN_HEIGHT - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT - RQ_APPLICATION_STATUS_BAR_HEIGHT - self.videoPlayerHeight - self.coverBgViewHeight - self.categoryViewHeight - 20); [self.view sendSubviewToBack:self.tableViewBgView]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; } #pragma mark - PrivateMethods /// 初始化 - (void)rq_setup { /// set up ... @weakify(self) self.tableView.backgroundColor = UIColor.clearColor; self.tableView.showsVerticalScrollIndicator = NO; [self.view addSubview:self.tableViewBgView]; [self.videoDetailSubPageSectionHeaderView.headerBtn setTitleNormal:self.viewModel.title]; self.videoDetailSubPageSectionHeaderView.headerSubTitleLabel.text = self.viewModel.subTitle; [[RACObserve(self.viewModel, updateDataType) takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable x) { @strongify(self) if (self.viewModel.updateDataType == RQVideoDetailSubPageUpdateDataType_Complete) { [RQNotificationCenter postNotificationName:RQPlayVideoUrlNotification object:@{ RQPlayVideoItemKey : self.viewModel.videoArr[self.viewModel.indexPath.row], RQPlayVideoItemArrKey : self.viewModel.videoArr, }]; } }]; } #pragma mark - OverrideMethods - (UIEdgeInsets)contentInset { return UIEdgeInsetsMake(0, 0, 0, 0); } - (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath { switch (indexPath.section) { case 0: { RQVideoDetailSubPageCell *cell = [RQVideoDetailSubPageCell cellWithTableView:tableView]; return cell; } default: return [super tableView:tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath]; } } - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object { switch (indexPath.section) { case 0: { RQVideoDetailSubPageCell *videoDetailSubPageCell = (RQVideoDetailSubPageCell *)cell; [videoDetailSubPageCell bindViewModel:object]; break; } default: { [super configureCell:cell atIndexPath:indexPath withObject:object]; break; } } } //- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { // return self.videoDetailSubPageSectionHeaderView; //} // //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { // return self.videoDetailSubPageSectionHeaderView.height; //} #pragma mark - JXCategoryListViewDelegate - (UIView *)listView { return self.view; } - (UIScrollView *)listScrollView { // NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.viewModel.indexPath.row inSection:0]; // NSArray *tableViewIndexPathArr = self.tableView.indexPathsForVisibleRows; // if ([tableViewIndexPathArr containsObject:indexPath]) { // [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:NO]; // } return self.tableView; } - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback { self.scrollCallback = callback; } #pragma mark - LazyLoad - (RQVideoDetailSubPageSectionHeaderView *)videoDetailSubPageSectionHeaderView { if (!_videoDetailSubPageSectionHeaderView) { _videoDetailSubPageSectionHeaderView = [RQVideoDetailSubPageSectionHeaderView videoDetailSubPageSectionHeaderView]; } return _videoDetailSubPageSectionHeaderView; } - (UIView *)tableViewBgView { if (!_tableViewBgView) { _tableViewBgView = [[UIView alloc] init]; _tableViewBgView.frame = self.tableView.frame; _tableViewBgView.alpha = 1.0; _tableViewBgView.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0]; _tableViewBgView.layer.shadowColor = [UIColor colorWithRed:124/255.0 green:129/255.0 blue:136/255.0 alpha:0.20].CGColor; _tableViewBgView.layer.shadowOffset = CGSizeMake(0,0); _tableViewBgView.layer.shadowRadius = 8; _tableViewBgView.layer.shadowOpacity = 1; _tableViewBgView.layer.cornerRadius = 10; [_tableViewBgView addSubview:self.videoDetailSubPageSectionHeaderView]; [self.videoDetailSubPageSectionHeaderView mas_remakeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(_tableViewBgView.mas_top).mas_offset(- self.coverBgViewHeight); make.centerX.mas_equalTo(_tableViewBgView); make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH, self.sectionHeaderViewHeight)); }]; } return _tableViewBgView; } - (float)videoPlayerHeight { return RQ_FIT_HORIZONTAL(210.f); } - (float)coverBgViewHeight { return ((self.videoDetailSubPageSectionHeaderView.headerBtn.height / 2.f) + 22); } - (float)sectionHeaderViewHeight { return RQ_FIT_HORIZONTAL(94.f); } - (float)categoryViewHeight { CGFloat cellWidth = (RQ_SCREEN_WIDTH - (8 * 3) - (16 * 2)) / 4.f; CGFloat toolHeight = (cellWidth) * (37.f / 80.f) + 2 * ((cellWidth) * (11 / 80.f) * (4.3f / 11.f)); return (self.viewModel.videoSourceType == RQVideoSourceType_LnJppt)? 0 : toolHeight; } @end