123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486 |
- //
- // XYChatRoomMainViewController.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2020/6/19.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "XYChatRoomMainViewController.h"
- #import "MLMSegmentManager.h"
- #import "XYChatRoomCollectionListViewController.h"
- #import "XYChatRoomCategoriesModel.h"
- #import "XYGesturesScrollView.h"
- #import "XYBannerListModel.h"
- @interface XYChatRoomMainViewController ()<UIScrollViewDelegate, SDCycleScrollViewDelegate, XYChatRoomCollectionListViewControllerDelegate>
- @property (nonatomic, strong) XYGesturesScrollView *mainScrollView;
- @property (nonatomic, strong) SDCycleScrollView *cycleScrollView;
- @property (nonatomic, strong) MLMSegmentHead *segmentHead;
- @property (nonatomic, strong) MLMSegmentScroll *segmentScroll;
- @property (nonatomic, strong) NSMutableArray *titles;
- // 语音分类数组
- @property (nonatomic, readwrite, strong) NSArray *voiceCategoryArray;
- @property (nonatomic, readwrite, strong) NSArray *categoryControllers;
- @property (nonatomic, strong) NSMutableArray *bannerDataScoure;
- // 主scrollView的顶部位移临界点,大于等于则不滚动主scrollView
- @property (nonatomic, assign) CGFloat scrollTopOffset;
- // 主scrollView是否可以滑动
- @property (nonatomic, assign) BOOL canScroll;
- // 从首页列表跳转过来第一次加载数据(防止index=0页数据为空)
- @property (nonatomic, assign) BOOL isFirstLoad;
- @end
- @implementation XYChatRoomMainViewController
- - (void)dealloc {
- [self removeChildViewControllerScrollTopNotification];
- }
- /// 重写init方法,配置你想要的属性
- - (instancetype)init
- {
- self = [super init];
- if (self) {
- // 是否隐藏该控制器的导航栏
- self.prefersNavigationBarHidden = YES;
- }
- return self;
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- if (self.cycleScrollView) {
- [self.cycleScrollView adjustWhenControllerViewWillAppera];
- }
- }
- - (void)viewDidLoad {
- if (self.isMyVoiceRoomCollect) {
- self.view.backgroundColor = Color_White;
- self.prefersNavigationBarHidden = NO;
- self.segmentHead.hidden = YES;
- self.title = @"我的收藏";
- }
-
- [super viewDidLoad];
-
- /// 设置
- [self _setup];
-
- /// 设置导航栏
- [self _setupNavigationItem];
-
- /// 设置子控件
- [self _setupSubViews];
-
- /// 布局子空间
- [self _makeSubViewsConstraints];
-
- // 滚动通知
- [self addChildViewControllerScrollTopNotification];
-
- // 添加下拉刷新
- [self addRefresh];
-
- //[self scrollViewDidTriggerHeaderRefresh:NO];
-
- [self base_reloadListData];
-
- }
- - (void)base_reloadListData {
- [self.mainScrollView.mj_header beginRefreshing];
- }
- - (void)addRefresh {
- /// 下拉刷新
- @weakify(self);
- [self.mainScrollView addImageHeaderRefresh:^(MJRefreshHeader *header) {
- /// 加载下拉刷新的数据
- @strongify(self);
- [self scrollViewDidTriggerHeaderRefresh:YES];
- }];
- }
- - (void)scrollViewDidTriggerHeaderRefresh:(BOOL)refreshList {
- if (self.isMyVoiceRoomCollect) {
- self.segmentScroll.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64-kiPhoneXTopEdge);
- self.mainScrollView.top = 64 + kiPhoneXTopEdge;
- self.mainScrollView.height = SCREEN_HEIGHT-64-kiPhoneXTopEdge;
- self.mainScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, self.segmentScroll.f_top);
-
- [self scrollInitValue];
- [self refreshCurrentList];
- //[self.mainScrollView.mj_header endRefreshing];
-
- }else{
- /// 获取banner
- [[XYConfigAPIManager new] getBannersWithBannerPosition:102 categoryId:@"-1" successHandler:^(ZYLResponseModel *responseModel) {
- [self.bannerDataScoure removeAllObjects];
- for (NSDictionary *dict in responseModel.data[@"list"]) {
- XYBannerListModel *model = XYBannerListModel.new;
- [model yy_modelSetWithDictionary:dict];
- [self.bannerDataScoure addObject:model];
- }
-
- if (self.bannerDataScoure.count > 0) {
- // 允许显示且banner数据不为空则可以显示
- NSMutableArray *images = NSMutableArray.new;
- for (XYBannerListModel *model in self.bannerDataScoure) {
- [images addObject:model.bannerPic];
- }
- self.cycleScrollView.frame = CGRectMake(16.0f, 8.0f, SCREEN_WIDTH - 32.0f, 100.0f);
- self.cycleScrollView.imageURLStringsGroup = [images copy];
- self.segmentHead.frame = CGRectMake(10.0f, self.cycleScrollView.f_top + 8.0f, SCREEN_WIDTH - 20.0f, 48.0f);
- }else {
- self.cycleScrollView.frame = CGRectMake(16.0f, 0.0f, SCREEN_WIDTH - 32.0f, 0.0f);
- self.segmentHead.frame = CGRectMake(10.0f, self.cycleScrollView.f_top, SCREEN_WIDTH - 20.0f, 48.0f);
- }
- [UIView animateWithDuration:0.3 animations:^{
- self.cycleScrollView.alpha = 1;
- }];
-
- self.segmentScroll.frame = CGRectMake(0, self.segmentHead.f_top, SCREEN_WIDTH, SCREEN_HEIGHT- NAVGATION_HEIGHT - self.segmentHead.f_heigh);
-
- self.mainScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, self.segmentScroll.f_top);
- [self scrollInitValue];
- if (refreshList) {[self refreshCurrentList];}
- //[self.mainScrollView.mj_header endRefreshing];
-
- } failureHandler:^(ZYLNetworkError *error) {
- [self scrollInitValue];
- if (refreshList) {[self refreshCurrentList];}
- //[self.mainScrollView.mj_header endRefreshing];
-
- }];
- }
-
- }
- - (void)refreshCurrentList {
- if (self->_segmentScroll) {
- XYChatRoomCollectionListViewController *currentVc = [self->_segmentScroll currentVcOrView];
- if ([currentVc isKindOfClass:[XYChatRoomCollectionListViewController class]]) {
- [currentVc collectionViewDidTriggerHeaderRefresh];
- if (!self.isFirstLoad) { self.isFirstLoad = YES;
- [self selectItemType:[AppDelegate sharedDelegate].tabbarVC.partyVCSelectType];
- }
- }
- }
- }
- #pragma mark — SDCycleScrollViewDelegate
- /** 点击图片回调 */
- - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
- // 派对Tab,点[banner]的次数
- [StatisticsManager event:@"party_banner_click"];
-
- XYBannerListModel *model = self.bannerDataScoure[index];
- [XYBannerListModel bannerClickHandleWithModel:model];
- }
- #pragma mark — XYChatRoomCollectionListViewControllerDelegate, XYChatRoomListViewControllerDelegate
- - (void)headerRefreshEnding {
- [self.mainScrollView.mj_header endRefreshing];
- }
- #pragma mark — scrollView 滑动处理----------------begin
- - (void)scrollInitValue {
- self.canScroll = YES;
- if (self.bannerDataScoure.count > 0) {
- self.scrollTopOffset = self.cycleScrollView.f_top + 8.0f;
- }else {
- self.scrollTopOffset = self.cycleScrollView.f_top;
- }
- }
- /// 添加子控制器滑动控件到达顶部的通知
- - (void)addChildViewControllerScrollTopNotification {
- [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeStatus) name:@"chatroom_controller_leave_top" object:nil];
- }
- /// 删除子控制器滑动控件到达顶部的通知
- - (void)removeChildViewControllerScrollTopNotification {
- [[NSNotificationCenter defaultCenter] removeObserver:self name:@"chatroom_controller_leave_top" object:nil];
- }
- - (void)changeStatus {
- // 更新状态
- self.canScroll = YES;
- for (XYChatRoomScrollCollectionViewController *vc in self.categoryControllers) {
- vc.canScroll = NO;
- }
- }
- - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
- // NSLog(@"scrollView--------开始拖动");
- }
- - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
- // NSLog(@"scrollView--------结束拖动");
- }
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
-
- // NSLog(@"scrollView=====滚动==%.2F",scrollView.contentOffset.y);
- /*
- 当 底层滚动式图滚动到指定位置时,
- 停止滚动,开始滚动子视图
- */
- if (scrollView.contentOffset.y >= self.scrollTopOffset) {
- scrollView.contentOffset = CGPointMake(0, self.scrollTopOffset);
- if (self.canScroll) {
- self.canScroll = NO;
- for (XYChatRoomScrollCollectionViewController *vc in self.categoryControllers) {
- vc.canScroll = YES;
- }
- }
- }else{
- if (!self.canScroll) {//子视图没到顶部
- scrollView.contentOffset = CGPointMake(0, self.scrollTopOffset);
- }
- }
- }
- - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
- // NSLog(@"scrollView--------减速");
- }
- /// 获取当前子控制器
- - (XYChatRoomScrollCollectionViewController *)getCurrentChildViewController {
- XYChatRoomScrollCollectionViewController *currentVc = (XYChatRoomScrollCollectionViewController *)[self.segmentScroll currentVcOrView];
- return currentVc;
- }
- #pragma mark — scrollView 滑动处理----------------end
- #pragma mark - 事件处理Or辅助方法
- #pragma mark - 初始化
- - (void)_setup{
-
- // 获取分类数据
- [self getLiveCategoryData];
- }
- #pragma mark - 设置导航栏
- - (void)_setupNavigationItem{
- }
- #pragma mark - 设置子控件
- - (void)_setupSubViews{
-
- [self.view addSubview:self.mainScrollView];
- [self.mainScrollView addSubview:self.cycleScrollView];
-
- // 初始化分类列表
- [self addLiveCategoriesView];
-
- // 初始化滑动值
- [self scrollInitValue];
- }
- - (void)addLiveCategoriesView {
- if (self.segmentHead) {
- [self.segmentHead removeFromSuperview];
- self.segmentHead = nil;
- }
- if (self.segmentScroll) {
- [self.segmentScroll removeFromSuperview];
- self.segmentScroll = nil;
- }
-
- self.titles = [NSMutableArray array];
- NSMutableArray *controllers = [NSMutableArray array];
- for (XYChatRoomCategoriesModel *model in self.voiceCategoryArray) {
- [self.titles addObject:model.categoryName];
- XYChatRoomCollectionListViewController *vc = [XYChatRoomCollectionListViewController new];
- vc.delegate = self;
- vc.categoriesModel = model;
- [controllers addObject:vc];
- }
-
- self.categoryControllers = [NSArray arrayWithArray:controllers];
-
- if (_segmentHead == nil) {
- _segmentHead = [[MLMSegmentHead alloc] initWithFrame:CGRectMake(10.0f, self.cycleScrollView.f_top + 8.0f, SCREEN_WIDTH - 20.0f, 48.0f) titles:self.titles headStyle:SegmentHeadStyleSlide layoutStyle:MLMSegmentLayoutLeft];
- _segmentHead.headColor = Color_Clear;
- _segmentHead.fontSize = 14;
- _segmentHead.selectColor = Color_White;
- _segmentHead.deSelectColor = ColorFromHexString(@"#969699");
- _segmentHead.slideColor = Color_TextRed;
- _segmentHead.slideDeSelectColor = ColorFromHexString(@"#F7F7FA");
- _segmentHead.slideHeight = 28.0f;
- _segmentHead.slideCorner = 14.0f;
- _segmentHead.slideScale = 0.8f;
- _segmentHead.singleW_Add = 40.0f;
-
- _segmentHead.equalSize = NO;
- _segmentHead.bottomLineHeight = 0;
-
- if (self.isMyVoiceRoomCollect) { _segmentHead.hidden = YES; }
-
- }
- if (_segmentScroll == nil) {
- kWEAKSELF
- _segmentScroll = [[MLMSegmentScroll alloc] initWithFrame:CGRectMake(0, self.segmentHead.f_top, SCREEN_WIDTH, SCREEN_HEIGHT- NAVGATION_HEIGHT - _segmentHead.f_heigh) vcOrViews:controllers];
- _segmentScroll.backgroundColor = Color_White;
- _segmentScroll.scrollEnd = ^(NSInteger index) {
- NSString *title = weakSelf.titles[index];
- if ([title isEqualToString:kLocalizedString(@"收藏")]) {
- // 派对Tab,点分类-[收藏]的次数
- [StatisticsManager event:@"party_sort_collection_click"];
- }else if ([title isEqualToString:kLocalizedString(@"热门")]) {
- // 派对Tab,点分类-[热门]的次数
- [StatisticsManager event:@"party_sort_hot_click"];
- }else if ([title isEqualToString:kLocalizedString(@"男神")]) {
- // 派对Tab,点分类-[男神]的次数
- [StatisticsManager event:@"party_sort_malegod_click"];
- }else if ([title isEqualToString:kLocalizedString(@"女神")]) {
- // 派对Tab,点分类-[女神]的次数
- [StatisticsManager event:@"party_sort_femalegod_click"];
- }else if ([title isEqualToString:kLocalizedString(@"点唱")]) {
- // 派对Tab,点分类-[点唱]的次数
- [StatisticsManager event:@"party_sort_sing_click"];
- }else if ([title isEqualToString:kLocalizedString(@"游戏")]) {
- // 派对Tab,点分类-[游戏]的次数
- [StatisticsManager event:@"party_sort_game_click"];
- }
- };
- }
-
- [MLMSegmentManager associateHead:_segmentHead withScroll:_segmentScroll completion:^{
- [self.mainScrollView addSubview:self.segmentHead];
- [self.mainScrollView addSubview:self.segmentScroll];
- }];
-
- self.mainScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, self.segmentScroll.f_top);
-
- }
- - (void)selectItemType:(XYPublicChatHallViewType )type{
- if (type == XYPublicChatHallViewType_HotRoom) {
- for (int i = 0 ; i < self.titles.count ; i++) {
- NSString *str = self.titles[i];
- if ([str isEqualToString:kLocalizedString(@"热门")]) {
- self.segmentHead.selectedIndex(i);
- }
- }
-
- }else if (type == XYPublicChatHallViewType_LoveRoom){
- for (int i = 0 ; i < self.titles.count ; i++) {
- NSString *str = self.titles[i];
- if ([str isEqualToString:kLocalizedString(@"相亲")]) {
- self.segmentHead.selectedIndex(i);
- }
- }
-
- }else if (type == XYPublicChatHallViewType_DispatchRoom){
- for (int i = 0 ; i < self.titles.count ; i++) {
- NSString *str = self.titles[i];
- if ([str isEqualToString:kLocalizedString(@"派单")]) {
- self.segmentHead.selectedIndex(i);
- }
- }
- }else if (type == XYPublicChatHallViewType_AuctionRoom){
- for (int i = 0 ; i < self.titles.count ; i++) {
- NSString *str = self.titles[i];
- if ([str isEqualToString:kLocalizedString(@"拍卖")]) {
- self.segmentHead.selectedIndex(i);
- }
- }
- }
-
- }
- - (void)getLiveCategoryData {
-
- if (self.isMyVoiceRoomCollect) {
- NSMutableArray *tempTitles = [NSMutableArray new];
- XYChatRoomCategoriesModel *collectModel = XYChatRoomCategoriesModel.new;
- collectModel.categoryName = kLocalizedString(@"收藏");
- collectModel.categoryId = @"";
- collectModel.chatRoom_Type = XYChatRoom_Type_Collect;
- collectModel.layout = XYVoiceRoomListLayoutOneGraphic;
- [tempTitles addObject:collectModel];
- self.voiceCategoryArray = [NSArray arrayWithArray:tempTitles];
-
- }else{
- NSMutableArray *tempTitles = [NSMutableArray new];
- NSArray *rtcRoomCategories = [ApplicationDelegate.appConfigModel.channelConfig.rtcRoomCategories copy];
-
- XYChatRoomCategoriesModel *hotModel = XYChatRoomCategoriesModel.new;
- hotModel.categoryName = kLocalizedString(@"热门");
- hotModel.categoryId = @"";
- hotModel.chatRoom_Type = XYChatRoom_Type_Hot;
- hotModel.layout = XYVoiceRoomListLayoutTwoBigImage;
- [tempTitles addObject:hotModel];
-
- for (NSDictionary *dict in rtcRoomCategories) {
- XYChatRoomCategoriesModel *defaultModel = XYChatRoomCategoriesModel.new;
- [defaultModel yy_modelSetWithDictionary:dict];
- defaultModel.chatRoom_Type = XYChatRoom_Type_Default;
- defaultModel.autoLoad = YES;
- if (defaultModel.makeFriend) {
- defaultModel.chatRoom_Type = XYChatRoom_Type_Friends;
- }
- [tempTitles addObject:defaultModel];
- }
-
- self.voiceCategoryArray = [NSArray arrayWithArray:tempTitles];
-
- }
- }
- #pragma mark - 布局子控件
- - (void)_makeSubViewsConstraints{
-
- }
- #pragma mark - Setter & Getter
- - (XYGesturesScrollView *)mainScrollView {
- if (!_mainScrollView) {
- _mainScrollView = [[XYGesturesScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.isMyVoiceRoomCollect ? SCREEN_HEIGHT : (SCREEN_HEIGHT - NAVGATION_HEIGHT))];
- _mainScrollView.delegate = self;
- _mainScrollView.showsVerticalScrollIndicator = NO;
- _mainScrollView.showsHorizontalScrollIndicator = NO;
- _mainScrollView.backgroundColor = [UIColor clearColor];
- if (@available(iOS 11.0, *)) {
- /// CoderMikeHe: 适配 iPhone X + iOS 11,
- AdjustsScrollViewInsets_Never(_mainScrollView);
- }
- }
- return _mainScrollView;
- }
- - (SDCycleScrollView *)cycleScrollView {
- if (!_cycleScrollView) {
- _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(10.0f, 0.0f, SCREEN_WIDTH - 20.0f, 0.0f) delegate:self placeholderImage:placeholderBannerImage()];
- _cycleScrollView.backgroundColor = Color_Clear;
- _cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
- // 是否无限循环
- _cycleScrollView.infiniteLoop = YES;
- // 是否自动滚动
- _cycleScrollView.autoScroll = YES;
- _cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
- _cycleScrollView.currentPageDotImage = [UIImage resizableImageWithColor:Color_White cornerRadius:4];
- _cycleScrollView.pageDotImage = [UIImage resizableImageWithColor:ColorFromHexStringWithAlpha(@"#000000", 0.4f) cornerRadius:4];
- [_cycleScrollView addViewBorder:Color_Clear redian:8.0f];
- _cycleScrollView.alpha = 0;
- }
- return _cycleScrollView;
- }
- - (NSMutableArray *)bannerDataScoure {
- if (!_bannerDataScoure) {
- _bannerDataScoure = [NSMutableArray array];
- }
- return _bannerDataScoure;
- }
- @end
|