| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157 |
- //
- // ZFNormalViewController.m
- // ZFPlayer
- //
- // Created by 紫枫 on 2018/3/21.
- // Copyright © 2018年 紫枫. All rights reserved.
- //
- #import "ZFNormalViewController.h"
- #import <ZFPlayer/ZFAVPlayerManager.h>
- #import <ZFPlayer/ZFIJKPlayerManager.h>
- #import <ZFPlayer/ZFPlayerControlView.h>
- #import "ZFNotAutoPlayViewController.h"
- #import <ZFPlayer/UIView+ZFFrame.h>
- #import <ZFPlayer/UIImageView+ZFCache.h>
- #import <ZFPlayer/ZFPlayerConst.h>
- #import "ZFUtilities.h"
- #import "PlayDetailBarView.h"
- #import "ZFPlayerControlView2.h"
- @import AVKit;
- static NSString *kVideoCover = @"";
- @interface ZFNormalViewController ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, strong) ZFPlayerController *player;
- @property (nonatomic, strong) UIImageView *containerView;
- @property (nonatomic, strong) ZFPlayerControlView2 *controlView;
- @property (nonatomic, strong) UIButton *playBtn;
- @property (nonatomic, strong) UIButton *changeBtn;
- @property (nonatomic, strong) UIButton *nextBtn;
- @property (nonatomic, strong) UIButton *pipBtn;
- @property (nonatomic, strong) NSArray <NSURL *>*assetURLs;
- @property (nonatomic, strong) AVPictureInPictureController *vc;
- @property (nonatomic, strong) UIScrollView *scrollView;
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) UITableView *tableView2;
- @property (nonatomic, strong) UITableView *tableView3;
- @property (nonatomic, assign) CGFloat sp;
- @property (nonatomic, assign) int episodes;
- @property (nonatomic, assign) int playQXDIndex;
- @property (nonatomic, strong) NSArray *reCommondMovies;
- @property (nonatomic, assign) float playProcess;
- @end
- @implementation ZFNormalViewController
- -(UIStatusBarStyle)preferredStatusBarStyle{
- return UIStatusBarStyleLightContent;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.sp = 1.0;
- self.episodes = 1;
- self.fd_prefersNavigationBarHidden = true;
- self.view.backgroundColor = [UIColor blackColor];
- self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Push" style:UIBarButtonItemStylePlain target:self action:@selector(pushNewVC)];
- [self.view addSubview:self.containerView];
-
- [self.containerView addSubview:self.playBtn];
- [self.view addSubview:self.changeBtn];
- [self.view addSubview:self.nextBtn];
- [self.view addSubview:self.pipBtn];
- [self setupPlayer];
- self.reCommondMovies = @[];
- [self setupui];
- // [self requestRecommondMovies];
- [self requestWatch];
-
- [self.controlView.bottomPgrogress addObserver:self forKeyPath:@"value" options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld) context:nil];
- }
- -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
- // NSLog(@"keyPath:%@,object:%@,change:%@,context:%@",keyPath,object,change,context);
- if([change[@"new"] floatValue] - self.playProcess >= 0.01){
- self.playProcess = [change[@"new"] floatValue];
- NSString * vid = [NSString stringWithFormat:@"%d",[self.playData[@"simple_info"][@"vid"] intValue]];
- NSDictionary *dic = [[NSUserDefaults standardUserDefaults] objectForKey:@"playProcessData"];
- if(dic){
- NSMutableDictionary *mdic = [NSMutableDictionary dictionary];
- [mdic addEntriesFromDictionary:dic];
- [mdic setValue:@([change[@"new"] floatValue]) forKey:vid];
- [[NSUserDefaults standardUserDefaults] setValue:mdic forKey:@"playProcessData"];
- NSLog(@"更新进度成功");
- }else{
- NSMutableDictionary *mdic = [NSMutableDictionary dictionary];
- [mdic setValue:@([change[@"new"] floatValue]) forKey:vid];
- [[NSUserDefaults standardUserDefaults] setValue:mdic forKey:@"playProcessData"];
- NSLog(@"更新进度成功");
- }
- }
- }
- -(void)dealloc{
- [self.controlView.bottomPgrogress removeObserver:self forKeyPath:@"value"];
- NSLog(@"zf dealloc");
- }
- -(void)requestWatch{
- @zf_weakify(self);
- [RequestTool post:@"watch/watchRequest" params:@{@"episodes":@(self.episodes),@"vid":@(self.vid)} success:^(id responseObject) {
- @zf_strongify(self);
- NSLog(@"watch/watchRequest-%@",responseObject);
- if([responseObject[@"code"] intValue] == 0){
- self.playData = [responseObject[@"data"] mutableCopy];
- //添加历史
- [UserModel addHistoryPlay:self.playData];
- //获取进度
- NSDictionary *dic = [[NSUserDefaults standardUserDefaults] objectForKey:@"processPlayVid"];
- NSString * vid = [NSString stringWithFormat:@"%d",[self.playData[@"simple_info"][@"vid"] intValue]] ;
- if(dic[vid]){
- self.playProcess = [dic[vid] floatValue];
- }else{
- self.playProcess = 0.0;
- }
-
- NSArray *arr = self.playData[@"video_urls"];
- if(![arr isKindOfClass:[NSArray class]] || arr.count == 0){
- NSString *toast = responseObject[@"msg"];
- if(![toast isKindOfClass:[NSString class]] || toast.length == 0){
- toast = @"暂无可播放资源";
- }
- [MBProgressHUD showMessage:toast];
- [self.player stop];
- self->_assetURLs = @[];
- [self.controlView resetControlView];
- NSLog(@"数据异常");
- return;
- }
- if(arr.count<=self.playQXDIndex){
- if(arr.count>0){
- self->_assetURLs = @[[NSURL URLWithString:self.playData[@"video_urls"][0]]];
- self.playQXDIndex = 0;
- }else{
- NSLog(@"数据异常");
- return;
- }
- }else{
- self->_assetURLs = @[[NSURL URLWithString:self.playData[@"video_urls"][self.playQXDIndex]]];
- }
- self.player.assetURLs = self.assetURLs;
-
- //测试代码
- // NSString *URLString = @"https://www.apple.com.cn/105/media/cn/airpods-pro/2022/d2deeb8e-83eb-48ea-9721-f567cf0fffa8/films/under-the-spell/airpods-pro-under-the-spell-tpl-cn-2022_16x9.m3u8";
- // self.player.assetURL = [NSURL URLWithString:URLString];
-
- [self.player playTheIndex:0];
- //self.playData[@"simple_info"][@"horizontal_cover_url"]
- [self.controlView showTitle:[NSString stringWithFormat:@"%@ 第%d集",self.playData[@"simple_info"][@"ch_name"],self.episodes] coverURLString:@"" fullScreenMode:ZFFullScreenModeAutomatic];
- [self.tableView reloadData];
-
- if(arr.count==1){
- self.controlView.landScapeControlView.pArr = @[@[@"480P",@"标清"]];
- }else if(arr.count == 2){
- self.controlView.landScapeControlView.pArr = @[@[@"720P",@"高清 SDR"],@[@"480P",@"标清"]];
- }else if(arr.count == 3){
- self.controlView.landScapeControlView.pArr = @[@[@"1080P",@"超清 SDR"],@[@"720P",@"高清 SDR"],@[@"480P",@"标清"]];
- }
- if(self.playQXDIndex == 0){
- self.controlView.landScapeControlView.defaultPIndex = (int)arr.count - 1;
- }else if(self.playQXDIndex == 1){
- self.controlView.landScapeControlView.defaultPIndex = (int)arr.count - 2;
- }else if(self.playQXDIndex == 2){
- self.controlView.landScapeControlView.defaultPIndex = (int)arr.count - 3;
- }
- // self.pArr = @[@[@"1080P",@"超清 SDR"],@[@"720P",@"高清 SDR"],@[@"480P",@"标清"]];
- [self requestRecommondMovies];
- }
- } failure:^(NSError *error) {}];
- }
- -(void)requestRecommondMovies{
- int vid = [self.playData[@"simple_info"][@"vid"] intValue];
- @zf_weakify(self);
- [RequestTool post:@"watch/getSameClassMovies" params:@{@"page":@{@"page":@(1),@"pageSize":@(9)},@"vid":@(vid)} success:^(id responseObject) {
- @zf_strongify(self);
- NSLog(@"watch/getSameClassMovies-%@",responseObject);
- if([responseObject[@"code"] intValue] == 0){
- NSLog(@"%@",responseObject);
- id list = responseObject[@"data"][@"list"];
- if([list isKindOfClass:[NSArray class]]){
- self.reCommondMovies = list;
- }else{
- self.reCommondMovies = @[];
- }
- [self.tableView reloadData];
- }
- } failure:^(NSError *error) {}];
- }
- -(void)setupui{
- PlayDetailBarView *pdb =[PlayDetailBarView new];
- [self.view addSubview:pdb];
- [pdb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 46));
- make.left.equalTo(self.view);
- make.top.equalTo(self.containerView.mas_bottom);
- }];
-
- [self.view addSubview:self.scrollView];
- [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(pdb.mas_bottom);
- make.left.equalTo(self.view);
- make.height.mas_equalTo(@(kScreenHeight - 46 - safetop - SCREEN_WIDTH*9/16));
- make.width.mas_equalTo(@(SCREEN_WIDTH));
- }];
-
- [self.scrollView addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(pdb.mas_bottom);
- make.left.equalTo(self.view);
- make.width.mas_equalTo(@(SCREEN_WIDTH));
- make.height.mas_equalTo(@(kScreenHeight - 46 - safetop - SCREEN_WIDTH*9/16));
- }];
-
- // [self.scrollView addSubview:self.tableView2];
- // [self.tableView2 mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.top.equalTo(pdb.mas_bottom);
- // make.left.equalTo(self.view).offset(SCREEN_WIDTH);
- // make.width.mas_equalTo(@(SCREEN_WIDTH));
- // make.height.mas_equalTo(@(kScreenHeight - 46 - safetop - SCREEN_WIDTH*9/16));
- // }];
-
- // [self.scrollView addSubview:self.tableView3];
- // [self.tableView3 mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.top.equalTo(pdb.mas_bottom);
- // make.left.equalTo(self.view).offset(SCREEN_WIDTH*2);
- // make.width.mas_equalTo(@(SCREEN_WIDTH));
- // make.height.mas_equalTo(@(kScreenHeight - 46 - safetop - SCREEN_WIDTH*9/16));
- // }];
-
- self.scrollView.contentSize = CGSizeMake(0, 0);
-
-
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- self.player.viewControllerDisappear = NO;
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- self.player.viewControllerDisappear = YES;
- }
- - (void)viewWillLayoutSubviews {
- [super viewWillLayoutSubviews];
- CGFloat x = 0;
- CGFloat y = safetop;
- //CGRectGetMaxY(self.navigationController.navigationBar.frame);
- CGFloat w = CGRectGetWidth(self.view.frame);
- CGFloat h = w*9/16;
- self.containerView.frame = CGRectMake(x, y, w, h);
-
- // w = 44;
- // h = w;
- // x = (CGRectGetWidth(self.containerView.frame)-w)/2;
- // y = (CGRectGetHeight(self.containerView.frame)-h)/2;
- // self.playBtn.frame = CGRectMake(x, y, w, h);
- //
- // w = 100;
- // h = 30;
- // x = (CGRectGetWidth(self.view.frame)-w)/2;
- // y = CGRectGetMaxY(self.containerView.frame)+50;
- // self.changeBtn.frame = CGRectMake(x, y, w, h);
- //
- // w = 100;
- // h = 30;
- // x = (CGRectGetWidth(self.view.frame)-w)/2;
- // y = CGRectGetMaxY(self.changeBtn.frame)+50;
- // self.nextBtn.frame = CGRectMake(x, y, w, h);
- //
- //
- // w = 100;
- // h = 30;
- // x = (CGRectGetWidth(self.view.frame)-w)/2;
- // y = CGRectGetMaxY(self.nextBtn.frame)+50;
- // self.pipBtn.frame = CGRectMake(x, y, w, h);
- }
- - (void)setupPlayer {
- ZFAVPlayerManager *playerManager = [[ZFAVPlayerManager alloc] init];
- // ZFIJKPlayerManager *playerManager = [[ZFIJKPlayerManager alloc] init];
- playerManager.shouldAutoPlay = YES;
-
- /// 播放器相关
- self.player = [ZFPlayerController playerWithPlayerManager:playerManager containerView:self.containerView];
- self.player.controlView = self.controlView;
- /// 设置退到后台继续播放
- self.player.pauseWhenAppResignActive = YES;
- // self.player.resumePlayRecord = YES;
-
- @zf_weakify(self)
- self.player.orientationDidChanged = ^(ZFPlayerController * _Nonnull player, BOOL isFullScreen) {
- /* // 使用YYTextView转屏失败
- for (UIWindow *window in [UIApplication sharedApplication].windows) {
- if ([window isKindOfClass:NSClassFromString(@"YYTextEffectWindow")]) {
- window.hidden = isFullScreen;
- }
- }
- */
- };
- /// 播放完成
- self.player.playerDidToEnd = ^(id _Nonnull asset) {
- @zf_strongify(self)
- if (!self.player.isLastAssetURL) {
- [self.player playTheNext];
- NSString *title = [NSString stringWithFormat:@"视频标题%zd",self.player.currentPlayIndex];
- [self.controlView showTitle:title coverURLString:kVideoCover fullScreenMode:ZFFullScreenModeLandscape];
- } else {
- [self.player stop];
- }
- };
- //修改播放速度
- self.player.playerPlayStateChanged = ^(id<ZFPlayerMediaPlayback> _Nonnull asset, ZFPlayerPlaybackState playState) {
- @zf_strongify(self)
- if(playState == ZFPlayerPlayStatePlaying){
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- ZFAVPlayerManager *manager = (ZFAVPlayerManager *)self.player.currentPlayerManager;
- manager.rate = self.sp;
- });
- }
- };
-
- }
- - (void)picBtnClick {
- /// 配置画中画
- ZFAVPlayerManager *manager = (ZFAVPlayerManager *)self.player.currentPlayerManager;
- AVPictureInPictureController *vc = [[AVPictureInPictureController alloc] initWithPlayerLayer:manager.avPlayerLayer];
- self.vc = vc;
- ///要有延迟 否则可能开启不成功
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.0*NSEC_PER_SEC), dispatch_get_main_queue(), ^{
- [self.vc startPictureInPicture];
- });
- }
- - (void)changeVideo:(UIButton *)sender {
- NSString *URLString = @"https://www.apple.com.cn/105/media/cn/airpods-pro/2022/d2deeb8e-83eb-48ea-9721-f567cf0fffa8/films/under-the-spell/airpods-pro-under-the-spell-tpl-cn-2022_16x9.m3u8";
- self.player.assetURL = [NSURL URLWithString:URLString];
- [self.controlView showTitle:@"AirPods" coverURLString:kVideoCover fullScreenMode:ZFFullScreenModeAutomatic];
- }
- - (void)playClick:(UIButton *)sender {
- [self.player playTheIndex:0];
- [self.controlView showTitle:@"视频标题" coverURLString:kVideoCover fullScreenMode:ZFFullScreenModeAutomatic];
- }
- - (void)nextClick:(UIButton *)sender {
- if (!self.player.isLastAssetURL) {
- [self.player playTheNext];
- NSString *title = [NSString stringWithFormat:@"视频标题%zd",self.player.currentPlayIndex];
- [self.controlView showTitle:title coverURLString:kVideoCover fullScreenMode:ZFFullScreenModeAutomatic];
- } else {
- NSLog(@"最后一个视频了");
- }
- }
- - (void)pushNewVC {
- ZFNotAutoPlayViewController *vc = [[ZFNotAutoPlayViewController alloc] init];
- [self.navigationController pushViewController:vc animated:YES];
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- __weak typeof (self) weakSelf = self;
- if(indexPath.row == 0){
- playercell1 * cell = [playercell1 cellWithTableView:tableView];
- cell.playData = self.playData;
- return cell;
- }else if(indexPath.row == 1){
- playercell2 * cell = [playercell2 cellWithTableView:tableView];
- cell.playData =self.playData;
-
- cell.changPlayBlock = ^(int index) {
- weakSelf.episodes = index;
- [weakSelf requestWatch];
- };
- return cell;
- }else if(indexPath.row == 2){
- playercell3 * cell = [playercell3 cellWithTableView:tableView];
- return cell;
- }else {
- playercell4 * cell = [playercell4 cellWithTableView:tableView];
- if((indexPath.row-3)*3 + 3>self.reCommondMovies.count){
- cell.reCommondMovies = [self.reCommondMovies subarrayWithRange:NSMakeRange((indexPath.row-3)*3, self.reCommondMovies.count-(indexPath.row-3)*3)];
- }else{
- cell.reCommondMovies = [self.reCommondMovies subarrayWithRange:NSMakeRange((indexPath.row-3)*3, 3)];
- }
- cell.tapBlock = ^(int index) {
- weakSelf.episodes = 1;
- weakSelf.vid = index;
- [weakSelf requestWatch];
- };
- return cell;
- }
-
- }
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- if(self.reCommondMovies.count%3==0){
- return 3+self.reCommondMovies.count/3;
- }else{
- return 3+self.reCommondMovies.count/3+1;
- }
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- if(indexPath.row == 0){
- return 80;
- }else if(indexPath.row == 1){
- return 122;
- }else if(indexPath.row == 2){
- return 46;
- }else {
- return 198;
- }
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
-
-
- }
- -(UIScrollView *)scrollView{
- if(!_scrollView){
- _scrollView =[UIScrollView new];
- _scrollView.showsVerticalScrollIndicator = false;
- _scrollView.showsHorizontalScrollIndicator = false;
- _scrollView.pagingEnabled = true;
- }
- return _scrollView;
- }
- -(UITableView *)tableView{
- if(!_tableView){
- _tableView =[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.showsVerticalScrollIndicator = false;
- _tableView.showsHorizontalScrollIndicator = false;
- _tableView.backgroundColor = rgba(18, 23, 41, 1);
- // _tableView.backgroundColor = [UIColor redColor];
- if (@available(iOS 11, *)) {
- _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- _tableView.estimatedRowHeight = 0;
- _tableView.estimatedSectionFooterHeight = 0;
- _tableView.estimatedSectionHeaderHeight = 0;
-
- UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
- UIEdgeInsets safeAreaInsets = keyWindow.safeAreaInsets;
- CGFloat topSafeArea = safeAreaInsets.top;
- _tableView.contentInset = UIEdgeInsetsMake(-topSafeArea, 0, 0, 0);
- // _tableView2.contentInset = UIEdgeInsetsMake(-35, 0, 0, 0);
- }
- #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 // only Xcode 13+ needs and can compile this
- if (@available(iOS 15.0, *)) {
- _tableView.sectionHeaderTopPadding = 0;
- }
- #endif
- }
- return _tableView;
- }
- -(UITableView *)tableView2{
- if(!_tableView2){
- _tableView2 =[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
- _tableView2.delegate = self;
- _tableView2.dataSource = self;
- _tableView2.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView2.showsVerticalScrollIndicator = false;
- _tableView2.showsHorizontalScrollIndicator = false;
- _tableView2.backgroundColor = rgba(18, 23, 41, 1);
- // _tableView.backgroundColor = [UIColor redColor];
- if (@available(iOS 11, *)) {
- _tableView2.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- _tableView2.estimatedRowHeight = 0;
- _tableView2.estimatedSectionFooterHeight = 0;
- _tableView2.estimatedSectionHeaderHeight = 0;
-
- UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
- UIEdgeInsets safeAreaInsets = keyWindow.safeAreaInsets;
- CGFloat topSafeArea = safeAreaInsets.top;
- _tableView2.contentInset = UIEdgeInsetsMake(-topSafeArea, 0, BAR_HEIGHT, 0);
- // _tableView2.contentInset = UIEdgeInsetsMake(-35, 0, 0, 0);
- }
- #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 // only Xcode 13+ needs and can compile this
- if (@available(iOS 15.0, *)) {
- _tableView2.sectionHeaderTopPadding = 0;
- }
- #endif
- }
- return _tableView2;
- }
- -(UITableView *)tableView3{
- if(!_tableView3){
- _tableView3 =[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
- _tableView3.delegate = self;
- _tableView3.dataSource = self;
- _tableView3.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView3.showsVerticalScrollIndicator = false;
- _tableView3.showsHorizontalScrollIndicator = false;
- _tableView3.backgroundColor = rgba(18, 23, 41, 1);
- // _tableView.backgroundColor = [UIColor redColor];
- if (@available(iOS 11, *)) {
- _tableView3.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- _tableView3.estimatedRowHeight = 0;
- _tableView3.estimatedSectionFooterHeight = 0;
- _tableView3.estimatedSectionHeaderHeight = 0;
-
- UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
- UIEdgeInsets safeAreaInsets = keyWindow.safeAreaInsets;
- CGFloat topSafeArea = safeAreaInsets.top;
- _tableView3.contentInset = UIEdgeInsetsMake(-topSafeArea, 0, BAR_HEIGHT, 0);
- // _tableView2.contentInset = UIEdgeInsetsMake(-35, 0, 0, 0);
- }
- #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 // only Xcode 13+ needs and can compile this
- if (@available(iOS 15.0, *)) {
- _tableView3.sectionHeaderTopPadding = 0;
- }
- #endif
- }
- return _tableView3;
- }
- //- (UIStatusBarStyle)preferredStatusBarStyle {
- // return UIStatusBarStyleDefault;
- //}
- - (BOOL)prefersStatusBarHidden {
- return NO;
- }
- - (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
- return UIStatusBarAnimationNone;
- }
- - (BOOL)shouldAutorotate {
- return NO;
- }
- - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
- return UIInterfaceOrientationMaskPortrait;
- }
- - (ZFPlayerControlView2 *)controlView {
- if (!_controlView) {
- _controlView = [ZFPlayerControlView2 new];
- _controlView.fastViewAnimated = YES;
- _controlView.effectViewShow = NO;
- _controlView.autoHiddenTimeInterval = 5;
- _controlView.autoFadeTimeInterval = 0.5;
- _controlView.prepareShowLoading = YES;
- _controlView.prepareShowControlView = NO;
- _controlView.showCustomStatusBar = YES;
- __weak typeof (self) weakSelf = self;
- _controlView.speedBtnClickCallback = ^(CGFloat sp){
- weakSelf.sp = sp;
- ZFAVPlayerManager *manager = (ZFAVPlayerManager *)weakSelf.player.currentPlayerManager;
- manager.rate = sp;
- };
- _controlView.clickBackBlock = ^{
- [weakSelf.navigationController popViewControllerAnimated:true];
- };
- _controlView.nextBtnClickCallback = ^{
- int total = [weakSelf.playData[@"simple_info"][@"total_episodes"] intValue];
- int current = weakSelf.episodes;
- if(current<total){
- weakSelf.episodes = current+1;
- [weakSelf requestWatch];
- }else{
- [MBProgressHUD showMessage:@"已是最后一集"];
- }
- };
- _controlView.pBtnClickCallback = ^(NSInteger index,int second) {
- NSString *URLString;
- NSArray *urls = weakSelf.playData[@"video_urls"];
- //1080p
- if(index == 0){
- //2
-
- URLString = weakSelf.playData[@"video_urls"][urls.count-1];
- weakSelf.playQXDIndex = (int)urls.count-1;
-
- //720p
- }else if(index == 1){
- //1
-
- URLString = weakSelf.playData[@"video_urls"][urls.count-2];
- weakSelf.playQXDIndex = (int)urls.count-2;
-
- //480p
- }else if(index == 2){
- //0
-
- URLString = weakSelf.playData[@"video_urls"][0];
- weakSelf.playQXDIndex = 0;
-
- }
- if(URLString.length > 0){
- weakSelf.player.assetURL = [NSURL URLWithString:URLString];
- //weakSelf.playData[@"simple_info"][@"horizontal_cover_url"]
- [weakSelf.controlView showTitle:weakSelf.playData[@"simple_info"][@"ch_name"] coverURLString:@"" fullScreenMode:ZFFullScreenModeAutomatic];
- [weakSelf.player seekToTime:second completionHandler:^(BOOL finished) {
-
- }];
- }
- };
- }
- return _controlView;
- }
- - (UIImageView *)containerView {
- if (!_containerView) {
- _containerView = [UIImageView new];
- [_containerView setImageWithURLString:kVideoCover placeholder:[ZFUtilities imageWithColor:[UIColor blackColor] size:CGSizeMake(1, 1)]];
- }
- return _containerView;
- }
- - (UIButton *)playBtn {
- if (!_playBtn) {
- _playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_playBtn setImage:[UIImage imageNamed:@"new_allPlay_44x44_"] forState:UIControlStateNormal];
- [_playBtn addTarget:self action:@selector(playClick:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _playBtn;
- }
- - (UIButton *)changeBtn {
- if (!_changeBtn) {
- _changeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
- [_changeBtn setTitle:@"Change video" forState:UIControlStateNormal];
- [_changeBtn addTarget:self action:@selector(changeVideo:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _changeBtn;
- }
- - (UIButton *)nextBtn {
- if (!_nextBtn) {
- _nextBtn = [UIButton buttonWithType:UIButtonTypeSystem];
- [_nextBtn setTitle:@"Next" forState:UIControlStateNormal];
- [_nextBtn addTarget:self action:@selector(nextClick:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _nextBtn;
- }
- - (UIButton *)pipBtn {
- if (!_pipBtn) {
- _pipBtn = [UIButton buttonWithType:UIButtonTypeSystem];
- [_pipBtn setTitle:@"开启画中画" forState:UIControlStateNormal];
- [_pipBtn addTarget:self action:@selector(picBtnClick) forControlEvents:UIControlEventTouchUpInside];
- }
- return _pipBtn;
- }
- - (NSArray<NSURL *> *)assetURLs {
- if (!_assetURLs) {
- _assetURLs = @[[NSURL URLWithString:self.playData[@"video_urls"][self.playQXDIndex]]];
- }
- return _assetURLs;
- }
- //[NSURL URLWithString:@"http://together-watch-mytest-bucket1.oss-cn-shanghai.aliyuncs.com/video%2Fuploads%2F1%2F1_1_480.mp4?Expires=1689755418&OSSAccessKeyId=LTAI5t8WGw2YFnQRRJ1oBNnb&Signature=mqlsqmxaOtRE065o1HXmu7mp4tw%3D"],[NSURL URLWithString:@"https://www.apple.com/105/media/us/iphone-x/2017/01df5b43-28e4-4848-bf20-490c34a926a7/films/feature/iphone-x-feature-tpl-cc-us-20170912_1280x720h.mp4"],
- // [NSURL URLWithString:@"https://www.apple.com/105/media/cn/mac/family/2018/46c4b917_abfd_45a3_9b51_4e3054191797/films/bruce/mac-bruce-tpl-cn-2018_1280x720h.mp4"],
- // [NSURL URLWithString:@"https://www.apple.com/105/media/us/mac/family/2018/46c4b917_abfd_45a3_9b51_4e3054191797/films/peter/mac-peter-tpl-cc-us-2018_1280x720h.mp4"],
- // [NSURL URLWithString:@"https://www.apple.com/105/media/us/mac/family/2018/46c4b917_abfd_45a3_9b51_4e3054191797/films/grimes/mac-grimes-tpl-cc-us-2018_1280x720h.mp4"],
- // [NSURL URLWithString:@"https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/7194236f31b2e1e3da0fe06cfed4ba2b.mp4"],
- // [NSURL URLWithString:@"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"],
- // [NSURL URLWithString:@"http://vjs.zencdn.net/v/oceans.mp4"],
- // [NSURL URLWithString:@"https://media.w3.org/2010/05/sintel/trailer.mp4"],
- // [NSURL URLWithString:@"http://mirror.aarnet.edu.au/pub/TED-talks/911Mothers_2010W-480p.mp4"],
- // [NSURL URLWithString:@"https://sample-videos.com/video123/mp4/480/big_buck_bunny_480p_2mb.mp4"]
- @end
- @interface playercell1()
- @end
- @implementation playercell1
- + (instancetype)cellWithTableView:(UITableView *)tableView{
- static NSString *identifier = @"playercell1";
- playercell1 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
- if (cell == nil) {
- cell = [[playercell1 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
- }
-
- return cell;
- }
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- [self creatView];
- }
- return self;
- }
- -(void)addCollectAct{
- int vid = [self.playData[@"simple_info"][@"vid"] intValue];
- UIButton *btn = [self.contentView viewWithTag:150];
- if([UserModel collectContainVid:vid]){
- [UserModel delCollect:self.playData[@"simple_info"]];
- [btn setImage:[UIImage imageNamed:@"Frame14"] forState:UIControlStateNormal];
- [btn setTitle:@" 收藏" forState:UIControlStateNormal];
- }else{
- [UserModel addCollect:self.playData[@"simple_info"]];
- [btn setTitle:@"已收藏" forState:UIControlStateNormal];
- [btn setImage:[UserModel imageWithColor:[UIColor clearColor]] forState:UIControlStateNormal];
- }
- }
- -(void)setPlayData:(NSDictionary *)playData {
- _playData = playData;
- UILabel *lab = [self.contentView viewWithTag:100];
- lab.text = playData[@"simple_info"][@"ch_name"];
-
- UILabel *lab2 = [self.contentView viewWithTag:101];
- lab2.text = [NSString stringWithFormat:@"%.1f分",[playData[@"simple_info"][@"score"] floatValue]];
-
- UILabel *lab3 = [self.contentView viewWithTag:102];
- NSArray *arr = playData[@"simple_info"][@"class_list"];
- NSString *t3=@"";
- for(int i=0;i<arr.count;i++){
- t3 = [NSString stringWithFormat:@"%@%@/",t3,arr[i][@"classname"]];
- }
- if(t3.length>0){
- lab3.text = [t3 substringToIndex:t3.length-1];
- }
-
-
- int vid = [playData[@"simple_info"][@"vid"] intValue];
- UIButton *btn = [self.contentView viewWithTag:150];
- if([UserModel collectContainVid:vid]){
- [btn setTitle:@"已收藏" forState:UIControlStateNormal];
- [btn setImage:[UserModel imageWithColor:[UIColor clearColor]] forState:UIControlStateNormal];
- }else{
- [btn setImage:[UIImage imageNamed:@"Frame14"] forState:UIControlStateNormal];
- [btn setTitle:@" 收藏" forState:UIControlStateNormal];
- }
- }
- -(void)creatView{
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.backgroundColor = [UIColor clearColor];
- UILabel *lab = [UILabel new];
- lab.text = @"勇敢者的游戏";
- lab.tag = 100;
- lab.textColor = rgba(255, 255, 255, 1);
- lab.font = [UIFont boldSystemFontOfSize:20];
- [self.contentView addSubview:lab];
- [lab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentView).offset(16);
- make.left.equalTo(self.contentView).offset(12);
- }];
-
- UILabel *lab2 = [UILabel new];
- lab2.text = @"9.6分";
- lab2.tag = 101;
- lab2.textColor = rgba(255, 212, 0, 1);
- lab2.font = [UIFont systemFontOfSize:12];
- lab2.backgroundColor = rgba(247, 187, 1, 0.2);
- lab2.textAlignment = NSTextAlignmentCenter;
- [self.contentView addSubview:lab2];
- [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(lab.mas_bottom).offset(14);
- make.left.equalTo(self.contentView).offset(12);
- make.size.mas_equalTo(CGSizeMake(50, 24));
- }];
-
- UILabel *lab3 = [UILabel new];
- lab3.tag = 102;
- lab3.text = @"悬疑/罪案/动作";
- lab3.textColor = rgba(255, 255, 255, 0.4);
- lab3.font = [UIFont systemFontOfSize:12];
- [self.contentView addSubview:lab3];
- [lab3 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(lab2);
- make.left.equalTo(lab2.mas_right).offset(6);
- }];
-
-
- UIButton *btn = [UIButton new];
- btn.tag = 150;
- [btn setImage:[UIImage imageNamed:@"Frame14"] forState:UIControlStateNormal];
- [btn setTitle:@" 收藏" forState:UIControlStateNormal];
- btn.titleLabel.font = [UIFont systemFontOfSize:12];
- [btn setTitleColor:rgba(255, 255, 255, 0.4) forState:UIControlStateNormal];
- [btn setBackgroundColor:rgba(255, 255, 255, 0.03)];
- [btn addTarget:self action:@selector(addCollectAct) forControlEvents:UIControlEventTouchUpInside];
- [self.contentView addSubview:btn];
- [btn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(lab2);
- make.right.equalTo(self.contentView).offset(-28);
- make.size.mas_equalTo(CGSizeMake(74, 30));
- }];
-
-
- lab2.layer.cornerRadius = 8;
- lab2.layer.masksToBounds = true;
- btn.layer.cornerRadius = 8;
- btn.layer.masksToBounds = true;
- }
- @end
- @interface playercell2()<UICollectionViewDelegate,UICollectionViewDataSource>
- @property(nonatomic,strong)UICollectionView *collect;
- @property(nonatomic,assign)int count;
- @end
- @implementation playercell2
- + (instancetype)cellWithTableView:(UITableView *)tableView{
- static NSString *identifier = @"playercell2";
- playercell2 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
- if (cell == nil) {
- cell = [[playercell2 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
- }
-
- return cell;
- }
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- [self creatView];
- }
- return self;
- }
- -(void)setPlayData:(NSDictionary *)playData{
- _playData = playData;
- self.count = [playData[@"simple_info"][@"total_episodes"] intValue];
- [self.collect reloadData];
- }
- -(void)creatView{
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.backgroundColor = [UIColor clearColor];
- UILabel *lab = [UILabel new];
- lab.text = @"选集";
- lab.textColor = rgba(255, 255, 255, 1);
- lab.font = [UIFont boldSystemFontOfSize:16];
- [self.contentView addSubview:lab];
- [lab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentView).offset(24);
- make.left.equalTo(self.contentView).offset(12);
- }];
-
- UILabel *lab2 = [UILabel new];
- // lab2.text = @"每周二、周三凌晨更新";
- lab2.textColor = rgba(255, 255, 255, 0.4);
- lab2.font = [UIFont systemFontOfSize:12];
- lab2.textAlignment = NSTextAlignmentCenter;
- [self.contentView addSubview:lab2];
- [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(lab);
- make.left.equalTo(lab.mas_right).offset(8);
- }];
-
- UIView *bg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-12, 64)];
- bg.backgroundColor = rgba(255, 255, 255, 0.03);
- [self.contentView addSubview:bg];
- [bg mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(12);
- make.top.equalTo(lab.mas_bottom).offset(12);
- make.right.equalTo(self.contentView);
- make.height.mas_equalTo(@64);
- // make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-12, 64));
- }];
-
- [self.contentView addSubview:self.collect];
- [self.collect mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(12);
- make.top.equalTo(lab.mas_bottom).offset(12);
- make.right.equalTo(self.contentView);
- make.height.mas_equalTo(@64);
- // make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-12, 64));
- }];
-
-
-
- // 创建圆角图层
- UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:bg.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft cornerRadii:CGSizeMake(8, 8)];
- CAShapeLayer *maskLayer = [CAShapeLayer layer];
- maskLayer.path = path.CGPath;
- bg.layer.mask = maskLayer;
-
- }
- -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
- playItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([playItemCell class]) forIndexPath:indexPath];
- cell.index = indexPath.row+1;
- if(indexPath.row == [self.playData[@"episodes"] intValue]-1){
- cell.isSel = true;
- }else{
- cell.isSel = false;
- }
- return cell;
- }
- -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- if(self.changPlayBlock){
- self.changPlayBlock((int)indexPath.row+1);
- }
- }
- -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
- return [self.playData[@"simple_info"][@"total_episodes"] intValue];
- }
- - (UICollectionView *)collect {
-
- if (!_collect) {
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.itemSize = CGSizeMake(48, 48);
- layout.minimumLineSpacing = 8; //跟滚动方向相同的间距
- // layout.minimumInteritemSpacing = 8; //跟滚动方向垂直的间距
- layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
- _collect = [[UICollectionView alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH-12, 64) collectionViewLayout:layout];
- _collect.contentInset = UIEdgeInsetsMake(8, 12, 8, 12);
- //注册cell
- [_collect registerClass:[playItemCell class] forCellWithReuseIdentifier:@"playItemCell"];
- // [_collect registerClass:[SearchItemCell class] forCellWithReuseIdentifier:@"SearchItemCell"];
- // [_collect registerClass:[FoundCell class] forCellWithReuseIdentifier:@"FoundCell"];
- // [_collect registerClass:[HotSearchCell class] forCellWithReuseIdentifier:@"HotSearchCell"];
- _collect.dataSource = self;
- _collect.delegate = self;
- _collect.backgroundColor = [UIColor clearColor];
-
-
- _collect.showsVerticalScrollIndicator = false;
- _collect.showsHorizontalScrollIndicator = false;
- }
- return _collect;
- }
- @end
- @interface playItemCell()
- @property(nonatomic,strong)UILabel *lab;
- @property(nonatomic,strong)UIImageView *iv;
- @end
- @implementation playItemCell
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- [self setUp];
- }
- return self;
- }
- -(void)setIndex:(NSInteger)index{
- _index = index;
- self.lab.text = [NSString stringWithFormat:@"%ld",(long)index];
- }
- - (void)setIsSel:(BOOL)isSel{
- _isSel = isSel;
- if(isSel){
- self.lab.backgroundColor = rgba(247, 187, 1, 0.2);
- self.lab.textColor = rgba(255, 212, 0, 1);
- self.iv.hidden = false;
- }else{
- self.lab.backgroundColor = rgba(18, 23, 41, 1);
- self.lab.textColor = rgba(255, 255, 255, 0.4);
- self.iv.hidden = true;
- }
- }
- - (void)setUp {
- self.backgroundColor = [UIColor clearColor];
- //选中背景 rgba(247, 187, 1, 0.2)
- UILabel *lab = [UILabel new];
- self.lab= lab;
- // lab.text = @"选集";
- lab.textColor = rgba(255, 255, 255, 0.4);
- lab.font = [UIFont boldSystemFontOfSize:16];
- lab.textAlignment = NSTextAlignmentCenter;
- [self.contentView addSubview:lab];
- [lab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.contentView);
- }];
-
- UIImageView *iv = [UIImageView new];
- iv.image = [UIImage imageNamed:@"Group 427319579"];
- self.iv = iv;
- [self.contentView addSubview:iv];
- [iv mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(6);
- make.bottom.equalTo(self.contentView).offset(-5);
- make.size.mas_equalTo(CGSizeMake(10, 10));
- }];
-
- self.lab.layer.cornerRadius = 8;
- self.lab.layer.masksToBounds = true;
- }
- @end
- @interface playercell3 ()
- @end
- @implementation playercell3
- + (instancetype)cellWithTableView:(UITableView *)tableView{
- static NSString *identifier = @"playercell3";
- playercell3 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
- if (cell == nil) {
- cell = [[playercell3 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
- }
-
- return cell;
- }
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- [self creatView];
- }
- return self;
- }
- -(void)creatView{
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.backgroundColor = [UIColor clearColor];
-
-
- UILabel *lab = [UILabel new];
- lab.text = @"猜你喜欢";
- lab.textColor = rgba(255, 255, 255, 1);
- lab.font = [UIFont boldSystemFontOfSize:16];
- [self.contentView addSubview:lab];
- [lab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentView).offset(24);
- make.left.equalTo(self.contentView).offset(12);
- }];
-
- UIImageView *iv = [UIImageView new];
- // iv.image = [UIImage imageNamed:@"Frame 9391"];
- [self.contentView addSubview:iv];
- [iv mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(lab);
- make.right.equalTo(self.contentView).offset(-12);
- make.size.mas_equalTo(CGSizeMake(12, 12));
- }];
-
- UILabel *lab2 = [UILabel new];
- // lab2.text = @"查看更多";
- lab2.textColor = rgba(255, 255, 255, 0.4);
- lab2.font = [UIFont systemFontOfSize:12];
- [self.contentView addSubview:lab2];
- [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(lab);
- make.right.equalTo(iv.mas_left);
- }];
- }
- @end
- @interface playercell4 ()
- @end
- @implementation playercell4
- + (instancetype)cellWithTableView:(UITableView *)tableView{
- static NSString *identifier = @"playercell4";
- playercell4 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
- if (cell == nil) {
- cell = [[playercell4 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
- }
-
- return cell;
- }
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- [self creatView];
- }
- return self;
- }
- -(void)setReCommondMovies:(NSArray *)reCommondMovies{
- _reCommondMovies = reCommondMovies;
- for(int i=0;i<3;i++){
- if(i<reCommondMovies.count){
- UIImageView *iv = [self.contentView viewWithTag:100+i];
- iv.hidden = false;
- [iv sd_setImageWithURL:[NSURL URLWithString:reCommondMovies[i][@"vertical_cover_url"]]];
-
- UILabel *lab = [self.contentView viewWithTag:200+i];
- lab.text = [NSString stringWithFormat:@"%.1f",[reCommondMovies[i][@"score"] floatValue]];
-
- UILabel *lab2 = [self.contentView viewWithTag:300+i];
- lab2.text = reCommondMovies[i][@"ch_name"];
- }else{
- UIImageView *iv = [self.contentView viewWithTag:100+i];
- iv.hidden = true;
- // [iv sd_setImageWithURL:[NSURL URLWithString:reCommondMovies[i][@"vertical_cover_url"]]];
-
- UILabel *lab = [self.contentView viewWithTag:200+i];
- lab.text = @"";
-
- UILabel *lab2 = [self.contentView viewWithTag:300+i];
- lab2.text = @"";
- }
- }
- }
- -(void)clickAct:(UITapGestureRecognizer *)g{
- NSInteger x = g.view.tag - 100;
- int vid = [self.reCommondMovies[x][@"vid"] intValue];
- if(self.tapBlock){
- self.tapBlock(vid);
- }
- }
- -(void)creatView{
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.backgroundColor = [UIColor clearColor];
- CGFloat m = (kScreenWidth - 3*112 - 24)/2;
- for(int i=0;i<3;i++){
- UIImageView *iv = [UIImageView new];
- iv.userInteractionEnabled = true;
- // iv.backgroundColor = [UIColor redColor];
- iv.tag = 100+i;
- iv.image = [UIImage imageNamed:@""];
- [self.contentView addSubview:iv];
- UITapGestureRecognizer *g = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickAct:)];
- [iv addGestureRecognizer:g];
- [iv mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(112, 146));
- make.left.equalTo(self.contentView).offset(12+(112+m)*i);
- make.top.equalTo(self.contentView).offset(12);
- }];
-
- UILabel *lab = [UILabel new];
- lab.text = @"9.7";
- lab.tag =200+i;
- lab.textColor = rgba(255, 212, 0, 1);
- lab.font = [UIFont boldSystemFontOfSize:16];
- [iv addSubview:lab];
- [lab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(iv).offset(-6);
- make.right.equalTo(iv).offset(-8);
- }];
-
- UILabel *lab2 = [UILabel new];
- lab2.text = @"摩天大楼";
- lab2.tag = 300+i;
- lab2.textColor = rgba(255, 255, 255, 1);
- lab2.font = [UIFont systemFontOfSize:14];
- [self.contentView addSubview:lab2];
- [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(iv.mas_bottom).offset(8);
- make.left.equalTo(iv);
- }];
-
- iv.layer.cornerRadius = 8;
- iv.layer.masksToBounds = true;
- }
- }
-
- @end
|