123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611 |
- //
- // MusicSquareViewController.m
- // KulexiuForStudent
- //
- // Created by 王智 on 2024/11/19.
- //
- #import "MusicSquareViewController.h"
- #import "MusicSquareNavView.h"
- #import "KSBaseWKWebViewController.h"
- #import "UserInfoManager.h"
- #import "HomeHotAlbumView.h"
- #import "HomeAlbumModel.h"
- #import "HomeHotAlbumCell.h"
- #import "HomeHotMusicView.h"
- #import "HomeNewMusicView.h"
- #import "HomeRecommendMusicView.h"
- #import "HomeHotMusicCollectionCell.h"
- #import "HomeMusicModel.h"
- #import "HomeMusicSheetLayout.h"
- #define COLLECTION_WIDTH ((NSInteger)(IS_IPAD ? KPortraitWidth * 0.7 : KPortraitWidth * 0.83))
- #define COLLECTION_HEIGHT (320)
- @interface MusicSquareViewController ()<UICollectionViewDelegate, UICollectionViewDelegateFlowLayout,UICollectionViewDataSource>
- @property (nonatomic, strong) MusicSquareNavView *navView;
- // 热门专辑
- @property (nonatomic, strong) HomeHotAlbumView *albumView;
- @property (nonatomic, strong) NSMutableArray *albumArray;
- @property (nonatomic, strong) UICollectionView *albumCollectionView; // 专辑容器
- @property (nonatomic, assign) CGFloat albumViewHeight; // album 高度
- // 推荐曲目
- @property (nonatomic, strong) HomeRecommendMusicView *recommendMusicView;
- @property (nonatomic, strong) UICollectionView *recommendMusicCollectionView; // 曲谱容器
- @property (nonatomic, strong) NSMutableArray *recommendMusicArray; // 曲谱数据
- @property (nonatomic, assign) CGFloat recommendMusicViewHeight; // music 高度
- // 最新曲目
- @property (nonatomic, strong) HomeNewMusicView *newestMusicView;
- @property (nonatomic, strong) UICollectionView *newestMusicCollectionView; // 曲谱容器
- @property (nonatomic, strong) NSMutableArray *newestMusicArray; // 曲谱数据
- @property (nonatomic, assign) CGFloat newestMusicViewHeight; // music 高度
- // 热门曲谱
- @property (nonatomic, strong) HomeHotMusicView *hotMusicView;
- @property (nonatomic, strong) UICollectionView *musicCollectionView; // 曲谱容器
- @property (nonatomic, strong) NSMutableArray *musicArray; // 曲谱数据
- @property (nonatomic, assign) CGFloat musicViewHeight; // music 高度
- @property (nonatomic, strong) dispatch_group_t requestGroup;
- @end
- @implementation MusicSquareViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.ks_prefersNavigationBarHidden = YES;
- [self configUI];
- }
- - (void)configUI {
- [self.view addSubview:self.navView];
- CGFloat navHeight = [MusicSquareNavView getViewHeight];
- [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.mas_equalTo(self);
- make.height.mas_equalTo(navHeight);
- }];
-
- [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.navView.mas_bottom);
- make.left.right.bottom.mas_equalTo(self.view);
- }];
-
- // 热门专辑
- [self.scrollView addSubview:self.albumView];
- self.albumViewHeight = [HomeHotAlbumView getViewHeight];
- [self.albumView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.scrollView.mas_top);
- make.height.mas_equalTo(self.albumViewHeight);
- }];
-
- // 推荐曲目
- [self.scrollView addSubview:self.recommendMusicView];
- self.recommendMusicViewHeight = [HomeRecommendMusicView getViewHeight];
- [self.recommendMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.albumView.mas_bottom);
- make.height.mas_equalTo(self.recommendMusicViewHeight);
- }];
-
- // 最新曲目
- [self.scrollView addSubview:self.newestMusicView];
- self.newestMusicViewHeight = [HomeNewMusicView getViewHeight];
- [self.newestMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.recommendMusicView.mas_bottom);
- make.height.mas_equalTo(self.newestMusicViewHeight);
- }];
-
- // 热门曲目
- [self.scrollView addSubview:self.hotMusicView];
- self.musicViewHeight = [HomeHotMusicView getViewHeight];
- [self.hotMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.newestMusicView.mas_bottom);
- make.height.mas_equalTo(self.musicViewHeight);
- make.bottom.mas_equalTo(self.scrollView.mas_bottom).offset(-10);
- }];
- MJWeakSelf;
- self.scrollView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
- [weakSelf requestData];
- }];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self requestData];
- }
- - (void)requestData {
- [self requestHotAlbum];
- [self requestHomeMusicMessage];
- dispatch_group_notify(self.requestGroup, dispatch_get_main_queue(), ^{
- [self.scrollView.mj_header endRefreshing];
- [self refreshView];
- });
- }
- - (void)requestHotAlbum {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager HomeHotAlbumRequest:KS_POST page:1 rows:10 version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSArray *sourceArray = [[dic ks_dictionaryValueForKey:@"data"] ks_arrayValueForKey:@"rows"];
- NSMutableArray *albumArray = [NSMutableArray array];
- for (NSDictionary *parm in sourceArray) {
- HomeAlbumModel *model = [[HomeAlbumModel alloc] initWithDictionary:parm];
- [albumArray addObject:model];
- }
- self.albumArray = [NSMutableArray arrayWithArray:albumArray];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
-
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)requestHomeMusicMessage {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager homeAppMusicSheetRequest:KS_POST version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
- NSArray *hotMusicSheet = [result ks_arrayValueForKey:@"hotMusicSheet"]; // 最热曲目
- NSMutableArray *hotArray = [NSMutableArray array];
- for (NSDictionary *parm in hotMusicSheet) {
- HomeMusicModel *model = [[HomeMusicModel alloc] initWithDictionary:parm];
- [hotArray addObject:model];
- }
- self.musicArray = [NSMutableArray arrayWithArray:hotArray];
-
- NSArray *newMusicSheet = [result ks_arrayValueForKey:@"newMusicSheet"]; // 最新曲目
- NSMutableArray *newMusicArray = [NSMutableArray array];
- for (NSDictionary *parm in newMusicSheet) {
- HomeMusicModel *model = [[HomeMusicModel alloc] initWithDictionary:parm];
- [newMusicArray addObject:model];
- }
- self.newestMusicArray = [NSMutableArray arrayWithArray:newMusicArray];
-
- NSArray *topMusicSheet = [result ks_arrayValueForKey:@"topMusicSheet"]; // 推荐曲目
- NSMutableArray *topMusicArray = [NSMutableArray array];
- for (NSDictionary *parm in topMusicSheet) {
- HomeMusicModel *model = [[HomeMusicModel alloc] initWithDictionary:parm];
- [topMusicArray addObject:model];
- }
- self.recommendMusicArray = [NSMutableArray arrayWithArray:topMusicArray];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)refreshView {
- [self refreshAlbumView];
- [self refreshMusicView];
- }
- - (void)refreshAlbumView {
- if (self.albumArray.count) {
- self.albumViewHeight = [HomeHotAlbumView getViewHeight];
- self.albumView.hidden = NO;
- }
- else {
- self.albumViewHeight = CGFLOAT_MIN;
- self.albumView.hidden = YES;
- }
- [self.albumView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.albumViewHeight);
- }];
- [self.albumCollectionView reloadData];
- }
- - (void)refreshMusicView {
- if (self.recommendMusicArray.count) {
- self.recommendMusicViewHeight = [HomeHotMusicView getViewHeight];
- self.recommendMusicView.hidden = NO;
- }
- else {
- self.recommendMusicViewHeight = CGFLOAT_MIN;
- self.recommendMusicView.hidden = YES;
- }
-
- [self.recommendMusicView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.recommendMusicViewHeight);
- }];
- [self.recommendMusicCollectionView reloadData];
-
- if (self.newestMusicArray.count) {
- self.newestMusicViewHeight = [HomeHotMusicView getViewHeight];
- self.newestMusicView.hidden = NO;
- }
- else {
- self.newestMusicViewHeight = CGFLOAT_MIN;
- self.newestMusicView.hidden = YES;
- }
-
- [self.newestMusicView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.newestMusicViewHeight);
- }];
- [self.newestMusicCollectionView reloadData];
-
- if (self.musicArray.count) {
- self.musicViewHeight = [HomeHotMusicView getViewHeight];
- self.hotMusicView.hidden = NO;
- }
- else {
- self.musicViewHeight = CGFLOAT_MIN;
- self.hotMusicView.hidden = YES;
- }
- [self.hotMusicView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.musicViewHeight);
- }];
- [self.musicCollectionView reloadData];
- }
- #pragma mark ---- collection data source
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- if (collectionView == self.albumCollectionView) { // 专辑
- return self.albumArray.count;
- }
- else if (collectionView == self.recommendMusicCollectionView) {
- NSInteger lastRowCount = (self.recommendMusicArray.count % 4) > 0 ? 1 : 0;
- NSInteger count = self.recommendMusicArray.count / 4 + lastRowCount;
- return count;
- }
- else if (collectionView == self.newestMusicCollectionView) {
- NSInteger lastRowCount = (self.newestMusicArray.count % 4) > 0 ? 1 : 0;
- NSInteger count = self.newestMusicArray.count / 4 + lastRowCount;
- return count;
- }
- else { // 乐谱
- NSInteger lastRowCount = (self.musicArray.count % 4) > 0 ? 1 : 0;
- NSInteger count = self.musicArray.count / 4 + lastRowCount;
- return count;
- }
- }
- - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- if (collectionView == self.albumCollectionView) {
- HomeAlbumModel *model = self.albumArray[indexPath.item];
- HomeHotAlbumCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotAlbumCell" forIndexPath:indexPath];
- [cell configWithAlbumModel:model];
- return cell;
- }
- else if (collectionView == self.recommendMusicCollectionView) {
- NSMutableArray *songArray = [NSMutableArray array];
- NSInteger length = indexPath.item * 4 + 4 > self.recommendMusicArray.count ? self.recommendMusicArray.count - indexPath.item * 4: 4;
- NSRange range = NSMakeRange(indexPath.item * 4, length);
-
- songArray = [NSMutableArray arrayWithArray:[self.recommendMusicArray subarrayWithRange:range]];
- HomeHotMusicCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotMusicCollectionCell" forIndexPath:indexPath];
- MJWeakSelf;
- [cell configWithSourceArray:songArray callback:^(NSString * _Nonnull songId) {
- [weakSelf displaySongDetail:songId];
- }];
- return cell;
- }
- else if (collectionView == self.newestMusicCollectionView) {
- NSMutableArray *songArray = [NSMutableArray array];
- NSInteger length = indexPath.item * 4 + 4 > self.newestMusicArray.count ? self.newestMusicArray.count - indexPath.item * 4: 4;
- NSRange range = NSMakeRange(indexPath.item * 4, length);
-
- songArray = [NSMutableArray arrayWithArray:[self.newestMusicArray subarrayWithRange:range]];
- HomeHotMusicCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotMusicCollectionCell" forIndexPath:indexPath];
- MJWeakSelf;
- [cell configWithSourceArray:songArray callback:^(NSString * _Nonnull songId) {
- [weakSelf displaySongDetail:songId];
- }];
- return cell;
- }
- else {
- NSMutableArray *songArray = [NSMutableArray array];
- NSInteger length = indexPath.item * 4 + 4 > self.musicArray.count ? self.musicArray.count - indexPath.item * 4: 4;
- NSRange range = NSMakeRange(indexPath.item * 4, length);
-
- songArray = [NSMutableArray arrayWithArray:[self.musicArray subarrayWithRange:range]];
- HomeHotMusicCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotMusicCollectionCell" forIndexPath:indexPath];
- MJWeakSelf;
- [cell configWithSourceArray:songArray callback:^(NSString * _Nonnull songId) {
- [weakSelf displaySongDetail:songId];
- }];
- return cell;
- }
- }
- - (void)displaySongDetail:(NSString *)songId {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/music-detail?id=",songId];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- if (collectionView == self.albumCollectionView) { // 专辑详情
- HomeAlbumModel *model = self.albumArray[indexPath.item];
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/music-album-detail/",model.internalBaseClassIdentifier];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- if (collectionView == self.albumCollectionView) {
- return CGSizeMake(100, 134);
- }
- else if (collectionView == self.recommendMusicCollectionView) {
- return CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT);
- }
- else if (collectionView == self.newestMusicCollectionView) {
- return CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT);
- }
- else {
- return CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT);
- }
- }
- #pragma mark ---- lazying
- - (dispatch_group_t)requestGroup {
- if (!_requestGroup) {
- _requestGroup = dispatch_group_create();
- }
- return _requestGroup;
- }
- - (MusicSquareNavView *)navView {
- if (!_navView) {
- _navView = [MusicSquareNavView sharedInstance];
- MJWeakSelf;
- [_navView topSearchAction:^{
- [weakSelf searchMusic];
- }];
- }
- return _navView;
- }
- - (void)searchMusic {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@/#/music-songbook/search", WEBHOST];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- #pragma mark ----- 专辑
- - (HomeHotAlbumView *)albumView {
- if (!_albumView) {
- _albumView = [HomeHotAlbumView shareInstance];
- MJWeakSelf;
- [_albumView homeAlbumMore:^{
- [weakSelf moreAlbumDetail];
- }];
- [_albumView.albumContentView addSubview:self.albumCollectionView];
- [self.albumCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.top.mas_equalTo(_albumView.albumContentView);
- }];
- }
- return _albumView;
- }
- - (UICollectionView *)albumCollectionView {
- if (!_albumCollectionView) {
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
- layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
- _albumCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- _albumCollectionView.backgroundColor = [UIColor clearColor];
- _albumCollectionView.delegate = self;
- _albumCollectionView.dataSource = self;
- _albumCollectionView.showsVerticalScrollIndicator = NO;
- _albumCollectionView.showsHorizontalScrollIndicator = NO;
- if (@available(iOS 11.0, *)) {
- _albumCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- if (@available(iOS 13.0, *)) {
- _albumCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
- } else {
- // Fallback on earlier versions
- }
- }
- [_albumCollectionView registerNib:[UINib nibWithNibName:@"HomeHotAlbumCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotAlbumCell"];
- }
- return _albumCollectionView;
- }
- - (void)moreAlbumDetail {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-album"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- #pragma mark --- 推荐曲目
- - (HomeRecommendMusicView *)recommendMusicView {
- if (!_recommendMusicView) {
- _recommendMusicView = [HomeRecommendMusicView shareInstance];
- MJWeakSelf;
- [_recommendMusicView homeMusicMore:^{
- [weakSelf moreRecommendMusic];
- }];
- [_recommendMusicView.musicContentView addSubview:self.recommendMusicCollectionView];
- [self.recommendMusicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.top.mas_equalTo(_recommendMusicView.musicContentView);
- }];
- }
- return _recommendMusicView;
- }
- - (UICollectionView *)recommendMusicCollectionView {
- if (!_recommendMusicCollectionView) {
- HomeMusicSheetLayout *layout = [[HomeMusicSheetLayout alloc] initWithSectionInset:UIEdgeInsetsMake(0, 11, 0, KPortraitWidth - COLLECTION_WIDTH) andMiniLineSapce:10 andMiniInterItemSpace:10 andItemSize:CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT)];
- _recommendMusicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- _recommendMusicCollectionView.backgroundColor = [UIColor clearColor];
- _recommendMusicCollectionView.delegate = self;
- _recommendMusicCollectionView.dataSource = self;
- _recommendMusicCollectionView.showsVerticalScrollIndicator = NO;
- _recommendMusicCollectionView.showsHorizontalScrollIndicator = NO;
- if (@available(iOS 11.0, *)) {
- _recommendMusicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- if (@available(iOS 13.0, *)) {
- _recommendMusicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
- } else {
- // Fallback on earlier versions
- }
- }
- [_recommendMusicCollectionView registerNib:[UINib nibWithNibName:@"HomeHotMusicCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotMusicCollectionCell"];
- }
- return _recommendMusicCollectionView;
- }
- - (NSMutableArray *)recommendMusicArray {
- if (!_recommendMusicArray) {
- _recommendMusicArray = [NSMutableArray array];
- }
- return _recommendMusicArray;
- }
- - (void)moreRecommendMusic {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-list"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- #pragma mark ---- 最新曲目
- - (HomeNewMusicView *)newestMusicView {
- if (!_newestMusicView) {
- if (!_newestMusicView) {
- _newestMusicView = [HomeNewMusicView shareInstance];
- MJWeakSelf;
- [_newestMusicView homeMusicMore:^{
- [weakSelf moreNewMusic];
- }];
- [_newestMusicView.musicContentView addSubview:self.newestMusicCollectionView];
- [self.newestMusicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.top.mas_equalTo(_newestMusicView.musicContentView);
- }];
- }
- return _newestMusicView;
- }
- return _newestMusicView;
- }
- - (UICollectionView *)newestMusicCollectionView {
- if (!_newestMusicCollectionView) {
- HomeMusicSheetLayout *layout = [[HomeMusicSheetLayout alloc] initWithSectionInset:UIEdgeInsetsMake(0, 11, 0, KPortraitWidth - COLLECTION_WIDTH) andMiniLineSapce:10 andMiniInterItemSpace:10 andItemSize:CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT)];
- _newestMusicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- _newestMusicCollectionView.backgroundColor = [UIColor clearColor];
- _newestMusicCollectionView.delegate = self;
- _newestMusicCollectionView.dataSource = self;
- _newestMusicCollectionView.showsVerticalScrollIndicator = NO;
- _newestMusicCollectionView.showsHorizontalScrollIndicator = NO;
- if (@available(iOS 11.0, *)) {
- _newestMusicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- if (@available(iOS 13.0, *)) {
- _newestMusicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
- } else {
- // Fallback on earlier versions
- }
- }
- [_newestMusicCollectionView registerNib:[UINib nibWithNibName:@"HomeHotMusicCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotMusicCollectionCell"];
- }
- return _newestMusicCollectionView;
- }
- - (NSMutableArray *)newestMusicArray {
- if (!_newestMusicArray) {
- _newestMusicArray = [NSMutableArray array];
- }
- return _newestMusicArray;
- }
- - (void)moreNewMusic {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-list"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
-
- #pragma mark ---- 热门曲目
- - (HomeHotMusicView *)hotMusicView {
- if (!_hotMusicView) {
- _hotMusicView = [HomeHotMusicView shareInstance];
- MJWeakSelf;
- [_hotMusicView homeMusicMore:^{
- [weakSelf moreHotMusic];
- }];
- [_hotMusicView.musicContentView addSubview:self.musicCollectionView];
- [self.musicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.top.mas_equalTo(_hotMusicView.musicContentView);
- }];
- }
- return _hotMusicView;
- }
- - (void)moreHotMusic {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-list"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (UICollectionView *)musicCollectionView {
- if (!_musicCollectionView) {
- HomeMusicSheetLayout *layout = [[HomeMusicSheetLayout alloc] initWithSectionInset:UIEdgeInsetsMake(0, 11, 0, KPortraitWidth - COLLECTION_WIDTH) andMiniLineSapce:10 andMiniInterItemSpace:10 andItemSize:CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT)];
- _musicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- _musicCollectionView.backgroundColor = [UIColor clearColor];
- _musicCollectionView.delegate = self;
- _musicCollectionView.dataSource = self;
- _musicCollectionView.showsVerticalScrollIndicator = NO;
- _musicCollectionView.showsHorizontalScrollIndicator = NO;
- if (@available(iOS 11.0, *)) {
- _musicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- if (@available(iOS 13.0, *)) {
- _musicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
- } else {
- // Fallback on earlier versions
- }
- }
- [_musicCollectionView registerNib:[UINib nibWithNibName:@"HomeHotMusicCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotMusicCollectionCell"];
- }
- return _musicCollectionView;
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|