123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- //
- // YOUPAILZHotMusicVC.m
- // YOUQU
- //
- // Created by CY on 2021/12/10.
- // Copyright © 2021 MS. All rights reserved.
- //
- #import "YOUPAILZHotMusicVC.h"
- #import "UIScrollView+LZRefresh.h"
- #import "YOUPAILZHotMusicCell.h"
- @interface YOUPAILZHotMusicVC ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, weak) UITextField *youpaipsearchTF;
- @property (nonatomic, weak) UIButton *cancelSearchBtn;
- @property (nonatomic, strong) NSString *youpaippageCode;
- @property (nonatomic, weak) UITableView *youpaiptableView;
- @property (nonatomic, strong) NSMutableArray <YOUPAILZMusicListItemModel *>*youpaipdataSource;
- @end
- @implementation YOUPAILZHotMusicVC
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- [self.view endEditing:YES];
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [self youpaifrequestMusicListWithStatus:kRefreshNormal];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifkeyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifkeyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
- [self youpaifinitUI];
-
- }
- - (void)youpaifinitUI{
-
- // UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 25.0f, 34.0f)];
- // UIImageView *searchImgV = [[UIImageView alloc] initWithFrame:CGRectMake(10.0f, 11.0f, 12.0f, 12.0f)];
- // searchImgV.image = [UIImage imageNamed:@"vqu_image_music_search"];
- // [leftView addSubview:searchImgV];
- // UITextField *searchTF = [[UITextField alloc]init];
- // searchTF.layer.cornerRadius = 17.0f;
- // searchTF.clipsToBounds = YES;
- // searchTF.tintColor = ZYPinkColor;
- // searchTF.leftViewMode = UITextFieldViewModeAlways;
- // searchTF.leftView = leftView;
- // searchTF.font = LCFont(11.0f);
- // NSMutableAttributedString* placeholder = [[NSMutableAttributedString alloc]initWithString:@"搜搜你喜欢的音乐、歌手"];
- // [placeholder addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0x6C6B70) range:NSMakeRange(0, placeholder.length)];
- // searchTF.attributedPlaceholder = placeholder;
- // searchTF.backgroundColor = [HexColorFromRGB(0x4F4B5B) colorWithAlphaComponent:0.43f];
- // searchTF.returnKeyType = UIReturnKeySearch;
- // searchTF.textColor = [UIColor whiteColor];
- // [self.view addSubview:searchTF];
- // self.youpaipsearchTF = searchTF;
- // [searchTF mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.left.offset(14.0f);
- // make.right.offset(-14.0f);
- // make.top.offset(12.0f);
- // make.height.offset(34.0f);
- // }];
- //
- // UIButton *cancelSearchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- // [cancelSearchBtn setTitle:@"取消" forState:UIControlStateNormal];
- // [cancelSearchBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- // cancelSearchBtn.titleLabel.font = LCFont(14.0f);
- // [cancelSearchBtn addTarget:self action:@selector(youpaifcancelSearchBtnClick) forControlEvents:UIControlEventTouchUpInside];
- // cancelSearchBtn.hidden = YES;
- // [self.view addSubview:cancelSearchBtn];
- // self.cancelSearchBtn = cancelSearchBtn;
- // [cancelSearchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.right.offset(-14.0f);
- // make.centerY.equalTo(searchTF);
- // }];
-
- UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- tableView.delegate = self;
- tableView.dataSource = self;
- tableView.rowHeight = 60.0f;
- tableView.estimatedRowHeight = 60.0f;
- tableView.estimatedSectionHeaderHeight = 0.0f;
- tableView.estimatedSectionFooterHeight = 0.0f;
- tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- tableView.backgroundColor = [UIColor clearColor];
- tableView.showsVerticalScrollIndicator = NO;
- [self.view addSubview:tableView];
- self.youpaiptableView = tableView;
- @weakify(self);
- [tableView setRefreshHeaderWithBlock:^{
- @strongify(self);
- [self youpaifrequestMusicListWithStatus:kRefreshHeader];
- }];
- [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.offset(0.0f);
- make.top.offset(0.0f);
- // make.top.equalTo(searchTF.mas_bottom).offset(12.0f);
- make.bottom.offset(-SafeHeight);
- }];
- }
- - (void)youpaifcancelSearchBtnClick{
- [self.view endEditing:YES];
- self.youpaipsearchTF.text = @"";
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return self.youpaipdataSource.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- NSString *cellID = @"YOUPAILZHotMusicCell";
- YOUPAILZHotMusicCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
- if (cell == nil) {
- cell = [[YOUPAILZHotMusicCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
- }
- [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.row]];
- return cell;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- return CGFLOAT_MIN;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
- return CGFLOAT_MIN;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- }
- //键盘即将隐藏
- - (void)youpaifkeyboardWillHide:(NSNotification *)note{
- [self.view layoutIfNeeded];
- if (self.keyboardWillHideBlock) {
- self.keyboardWillHideBlock();
- }
- self.cancelSearchBtn.hidden = YES;
- [self.view layoutIfNeeded];
- [UIView animateWithDuration:0.25f animations:^{
- [self.youpaipsearchTF mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(14.0f);
- make.right.offset(-14.0f);
- make.top.offset(12.0f);
- make.height.offset(34.0f);
- }];
- [self.view layoutIfNeeded];
- }];
- }
- //键盘即将弹出
- - (void)youpaifkeyboardWillShow:(NSNotification *)note{
- CGRect keyboardF = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
- CGFloat keyboardH = keyboardF.size.height;
- if (self.keyboardWillShowBlock) {
- self.keyboardWillShowBlock(keyboardH);
- }
- self.cancelSearchBtn.hidden = NO;
- [self.view layoutIfNeeded];
- [UIView animateWithDuration:0.25f animations:^{
- [self.youpaipsearchTF mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(14.0f);
- make.right.equalTo(self.cancelSearchBtn.mas_left).offset(-10.0f);
- make.top.offset(12.0f);
- make.height.offset(34.0f);
- }];
- [self.view layoutIfNeeded];
- }];
- }
- /// 设置加载更多
- - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{
- __weak typeof(self) weakSelf = self;
- [self.youpaiptableView setRefreshFooter:hidden withBlock:^{
- [weakSelf youpaifrequestMusicListWithStatus:kRefreshFooter];
- }];
- }
- /// 获取列表数据
- - (void)youpaifrequestMusicListWithStatus:(kRefreshStatus)status{
- if (status != kRefreshFooter) {
- self.youpaippageCode = @"0";
- }
- @weakify(self);;
- [LCHttpHelper requestWithURLString:GetAllSongs parameters:@{@"pageCode":self.youpaippageCode,@"number":@(10)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- @strongify(self);;
- [self.youpaiptableView endRefreshing:kRefreshAll];
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {//成功
- if (status != kRefreshFooter) {
- [self.youpaipdataSource removeAllObjects];
- }
- NSDictionary *data = [dict objectForKey:@"data"];
- NSArray <YOUPAILZMusicListItemModel *>*list = [YOUPAILZMusicListItemModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"list"]];
- [self.youpaipdataSource addObjectsFromArray:list];
- [self.youpaiptableView reloadData];
- // NSInteger totalCount = [[[data objectForKey:@"meta"] objectForKey:@"totalCount"] integerValue];
- self.youpaippageCode = [data objectForKey:@"pageCode"];
- [self youpaifrefreshFooterWithHidden:NO];
- }
- } failure:^(NSError *error) {
- [self.youpaiptableView endRefreshing:kRefreshAll];
- }];
- }
- - (NSMutableArray *)youpaipdataSource{
- if (!_youpaipdataSource) {
- _youpaipdataSource = [NSMutableArray array];
- }
- return _youpaipdataSource;
- }
- #pragma mark - JXCategoryListContentViewDelegate
- - (UIView *)listView{
- return self.view;
- }
- @end
|