日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

IOS基础之仿酷狗音乐第1天

發布時間:2023/12/18 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 IOS基础之仿酷狗音乐第1天 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

IOS基礎之仿酷狗音樂第1天

細節較多,涉及字典轉模型,tableView 的使用,模態框,自定義模態,音視頻播放,全局PCH文件,xib加載,自定義 xib ,info。plist文件的加載,動畫的使用等
如果對OC不熟悉的人,照葫蘆畫瓢也不一定畫出來,到處報錯。天道酬勤,工夫和時間花到了,得心應手,就不怕報錯。
關鍵性的代碼如下,源碼在我的主頁下面。項目名稱:02-黑馬音樂第一天.zip

// // HMMusicsViewController.m // 002-黑馬音樂 // // Created by 魯軍 on 2021/4/23. //#import "HMMusicsViewController.h" #import "HMMusic.h" #import "HMMusicCell.h" #import "HMPlayingViewController.h"@interface HMMusicsViewController () @property(nonatomic,strong)NSArray *musics; @property(nonatomic,strong)HMPlayingViewController *playingVc; @end @implementation HMMusicsViewController - (HMPlayingViewController *)playingVc{if(!_playingVc){self.playingVc = [[HMPlayingViewController alloc] init];}return _playingVc; } -(NSArray *)musics{if(!_musics){_musics = [HMMusic musicWithFilename:@"Musics.plist"];}return _musics; } - (void)viewDidLoad {[super viewDidLoad];// NSLog(@"%lu",self.musics.count);} #pragma mark - Table view data source - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {return self.musics.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {HMMusicCell *cell=[HMMusicCell cellWithTableView:tableView];cell.music = self.musics[indexPath.row];return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{return 70; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{[tableView deselectRowAtIndexPath:indexPath animated:YES];//取消黑框[self.playingVc show]; } @end // // HMPlayingViewController.m // 002-黑馬音樂 // // Created by 魯軍 on 2021/4/23. // #import "HMPlayingViewController.h" @interface HMPlayingViewController () @end @implementation HMPlayingViewController - (void)viewDidLoad {[super viewDidLoad]; } - (void)show{UIWindow *window = [[UIApplication sharedApplication].windows lastObject];self.view.frame = window.bounds;[window addSubview:self.view];self.view.y = self.view.height;[UIView animateWithDuration:0.4 animations:^{self.view.y = 0;}]; } @end // // HMMusic.h // 002-黑馬音樂 // // Created by 魯軍 on 2021/4/23. // #import <Foundation/Foundation.h> NS_ASSUME_NONNULL_BEGIN @interface HMMusic : NSObject @property(nonatomic,copy)NSString *name; @property(nonatomic,copy)NSString *icon; @property(nonatomic,copy)NSString *filename; @property(nonatomic,copy)NSString *lrcname; @property(nonatomic,copy)NSString *singer; @property(nonatomic,copy)NSString *singerIcon; -(instancetype)initWithDict:(NSDictionary *)dict; +(instancetype)musicWithDict:(NSDictionary *)dict; +(NSArray *)musicWithFilename:(NSString *)filename; @end NS_ASSUME_NONNULL_END // // HMMusic.m // 002-黑馬音樂 // // Created by 魯軍 on 2021/4/23. #import "HMMusic.h" @implementation HMMusic - (instancetype)initWithDict:(NSDictionary *)dict{self = [super init];if(self){[self setValuesForKeysWithDictionary:dict];}return self; } + (instancetype)musicWithDict:(NSDictionary *)dict{return [[self alloc] initWithDict:dict]; } +(NSArray *)musicWithFilename:(NSString *)filename{NSString *path = [[NSBundle mainBundle] pathForResource:filename ofType:nil];NSArray *array = [NSArray arrayWithContentsOfFile:path];NSMutableArray *mArray = [NSMutableArray array];for(NSDictionary *dict in array){[mArray addObject:[self musicWithDict:dict]];}return mArray; } @end // // HMMusicCell.h // 002-黑馬音樂 // // Created by 魯軍 on 2021/4/23. //#import <UIKit/UIKit.h> NS_ASSUME_NONNULL_BEGIN @class HMMusic; @interface HMMusicCell : UITableViewCell @property(nonatomic,strong)HMMusic *music; +(instancetype)cellWithTableView:(UITableView *)tableView; @end NS_ASSUME_NONNULL_END // // HMMusicCell.m // 002-黑馬音樂 // // Created by 魯軍 on 2021/4/23. #import "HMMusicCell.h" #import "HMMusic.h" #import "Colours.h" #import "UIImage+MJ.h" @implementation HMMusicCell + (instancetype)cellWithTableView:(UITableView *)tableView{static NSString *ID=@"music";HMMusicCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];if(cell==nil){cell = [[HMMusicCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];}return cell; } - (void)setMusic:(HMMusic *)music{_music = music;self.textLabel.text = music.name;self.detailTextLabel.text = music.singer;self.imageView.image = [UIImage circleImageWithName:music.singerIcon borderWidth:2 borderColor:[UIColor pinkColor]]; } @end 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的IOS基础之仿酷狗音乐第1天的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。