| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304 |
- //
- // ViewController.m
- // chinaTV
- //
- // Created by 刘伟伟 on 2023/7/5.
- //
- #import "ViewController.h"
- #import "HomeCommonBarView.h"
- #import "CTPageControl.h"
- #import "ZFNormalViewController.h"
- #import "SearchCommonBarView.h"
- #import "SearchResultViewController.h"
- #import <MJRefresh.h>
- @interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
- @property(nonatomic,strong)HomeCommonBarView *customerbar;
- @property(nonatomic,strong)SearchCommonBarView *homeSearchBar;
- @property(nonatomic,strong)UITableView *tableView;
- @property(nonatomic,strong)NSDictionary *homePageData;
- @property(nonatomic,strong)NSMutableArray *todayCommondData;
- @property(nonatomic,assign)int vid;
- @property(nonatomic,assign)int tb1footpage;
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.tb1footpage = 1;
- self.todayCommondData = [NSMutableArray array];
- [self setupUI];
- [self requestHomePageData];
- }
- -(void)requestHomePageData{
- if(![UserModel userToken]){
- [RequestTool post:@"user/userLogin" params:@{@"account":@"test",@"password":@"123456"} success:^(id responseObject) {
- NSLog(@"%@",responseObject);
- [[NSUserDefaults standardUserDefaults] setValue:responseObject[@"data"] forKey:@"existUserData"];
- [self requestHomePageData2];
- } failure:^(NSError *error) {
- NSLog(@"%@",error);
- }];
- }else{
- [self requestHomePageData2];
- }
- }
- -(void)todayReCommond{
- //今日推荐
- if(self.tb1footpage>10){
- [self.tableView.mj_footer endRefreshing];
- return;
- }
- [RequestTool post:@"home/dailyRecommend" params:@{@"page":@{@"page":@(self.tb1footpage),@"pageSize":@(9)}} success:^(id responseObject) {
- NSLog(@"home/dailyRecommend-%@",responseObject);
- if([responseObject[@"code"] intValue] == 0){
- NSArray *temp = responseObject[@"data"][@"list"];
- if(![temp isKindOfClass:[NSNull class]] && temp.count>0){
- [self.todayCommondData addObjectsFromArray:temp];
- // [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:2] withRowAnimation:UITableViewRowAnimationNone];
- [self.tableView reloadData];
- }
- [self.tableView.mj_footer endRefreshing];
- }
- } failure:^(NSError *error) {
- [self.tableView.mj_footer endRefreshing];
- }];
- }
- -(void)homeSearchWithKeyword:(NSString *)keyword{
- NSString *trimmed = [[keyword stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] copy];
- if(trimmed.length == 0){
- return;
- }
- [self.view endEditing:YES];
- NSMutableArray *history = [NSMutableArray array];
- id storedHistory = [[NSUserDefaults standardUserDefaults] objectForKey:@"mylocationhistory"];
- if([storedHistory isKindOfClass:[NSArray class]]){
- [history addObjectsFromArray:(NSArray *)storedHistory];
- }
- if(![history containsObject:trimmed]){
- [history addObject:trimmed];
- [[NSUserDefaults standardUserDefaults] setObject:history forKey:@"mylocationhistory"];
- }
- SearchResultViewController *vc = [SearchResultViewController new];
- vc.txt = trimmed;
- vc.hidesBottomBarWhenPushed = true;
- [self.navigationController pushViewController:vc animated:true];
- }
- -(void)requestHomePageData2{
- //首页数据
- [RequestTool post:@"home/homePage" params:@{} success:^(id responseObject) {
- NSLog(@"home/homePage-%@",responseObject);
- if([responseObject[@"code"] intValue] == 0){
- self.homePageData = responseObject[@"data"];
- [self.tableView reloadData];
- }
- } failure:^(NSError *error) {}];
- [self todayReCommond];
- // 推荐相关逻辑已移除
- }
- -(void)setupUI{
- self.fd_prefersNavigationBarHidden = true;
- [self.view addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.view);
- }];
- [self.tableView reloadData];
- [self.view addSubview:self.customerbar];
- [self.view bringSubviewToFront:self.customerbar];
- self.homeSearchBar.frame = self.customerbar.bounds;
- self.homeSearchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- [self.customerbar addSubview:self.homeSearchBar];
- __weak typeof (self) weakSelf = self;
- self.customerbar.changeTitAction = nil;
- self.customerbar.changeActionToFirst = ^{
- CGPoint point=weakSelf.tableView.contentOffset;
- if(point.y<100){
- weakSelf.customerbar.imageView.hidden = true;
- weakSelf.customerbar.bgView.backgroundColor = [UIColor clearColor];
- weakSelf.homeSearchBar.backgroundColor = [UIColor clearColor];
- }
- };
-
- }
- -(UIStatusBarStyle)preferredStatusBarStyle{
- return UIStatusBarStyleLightContent;
- }
- //监听scrollView滑动
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- if (scrollView == self.tableView) {
- CGFloat offsetY = scrollView.contentOffset.y;
- // NSLog(@"%f",offsetY);
- if(offsetY > 100 && self.customerbar.imageView.isHidden){
- self.customerbar.imageView.hidden = false;
- self.customerbar.bgView.backgroundColor = rgba(18, 23, 41, 1);
- self.homeSearchBar.backgroundColor = rgba(18, 23, 41, 1);
- }
- if(offsetY<=100 && !self.customerbar.imageView.isHidden){
- self.customerbar.imageView.hidden = true;
- self.customerbar.bgView.backgroundColor = [UIColor clearColor];
- self.homeSearchBar.backgroundColor = [UIColor clearColor];
- }
- }
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- if(tableView == self.tableView){
- if(section == 0){
- return 0;
- }else{
- return 54;
- }
- }
- return 0;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
- return 0.01;
- }
- -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
- if(tableView == self.tableView){
- if(section == 1){
- headerView *header = [[headerView alloc] init];
- header.title = @"热门影视";
- return header;
- }else if(section == 2){
- headerView *header = [[headerView alloc] init];
- header.title = @"今日推荐";
- return header;
- }
- }
- return [UIView new];
- }
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- if(tableView == self.tableView){
- return 3;
- }
- return 0;
- }
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- if(tableView == self.tableView){
- if(section == 2){
- if(self.todayCommondData.count%3==0){
- return self.todayCommondData.count/3;
- }else{
- return self.todayCommondData.count/3 + 1;
- }
- }else{
- return 1;
- }
- }
- return 0;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- if(tableView == self.tableView){
- if(indexPath.section == 0){
- return kScreenWidth*340/375;
- }else if(indexPath.section ==1){
- return 268;
- }else {
- return 214;
- }
- }
- return 0;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- __weak typeof (self) weakSelf = self;
- if(tableView == self.tableView){
- if(indexPath.section == 0){
- homecell1 *cell = [homecell1 cellWithTableView:tableView];
- cell.banner = self.homePageData[@"banners"];
- cell.tapBlock = ^(int index) {
- weakSelf.vid = index;
- [weakSelf playItem];
- };
- return cell;
- }else if(indexPath.section == 1){
- homecell2 *cell = [homecell2 cellWithTableView:tableView];
- cell.hotmovies = self.homePageData[@"hot_movies"];
- cell.tapBlock = ^(int index) {
- weakSelf.vid = index;
- [weakSelf playItem];
- };
- return cell;
- }else{
- homecell3 *cell = [homecell3 cellWithTableView:tableView];
- if(indexPath.row*3 + 3>self.todayCommondData.count){
- cell.todayCommond = [self.todayCommondData subarrayWithRange:NSMakeRange(indexPath.row*3, self.todayCommondData.count-indexPath.row*3)];
- }else{
- cell.todayCommond = [self.todayCommondData subarrayWithRange:NSMakeRange(indexPath.row*3, 3)];
- }
- cell.tapBlock = ^(int index) {
- weakSelf.vid = index;
- [weakSelf playItem];
- };
- return cell;
- }
- }
- return nil;
- }
- -(void)playItem{
- ZFNormalViewController *vc = [[ZFNormalViewController alloc] init];
- vc.vid = self.vid;
- vc.hidesBottomBarWhenPushed = true;
- [self.navigationController pushViewController:vc animated:true];
- }
- -(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);
- __weak typeof(self) weakSelf = self;
- _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
- weakSelf.tb1footpage += 1;
- [weakSelf todayReCommond];
- }];
- // _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(iphoneX ? -topSafeArea : -35 , 0, BAR_HEIGHT, 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;
- }
- -(SearchCommonBarView *)homeSearchBar{
- if(!_homeSearchBar){
- _homeSearchBar = [[SearchCommonBarView alloc] initWithFrame:CGRectZero];
- _homeSearchBar.backgroundColor = [UIColor clearColor];
- __weak typeof(self) weakSelf = self;
- _homeSearchBar.searchAction = ^(NSString * _Nonnull tit) {
- [weakSelf homeSearchWithKeyword:tit];
- };
- }
- return _homeSearchBar;
- }
- -(HomeCommonBarView *)customerbar{
- if(!_customerbar){
- CGFloat h=0;
- if(@available(iOS 13.0, *)){
- UIStatusBarManager *sc= [UIApplication sharedApplication].windows.firstObject.windowScene.statusBarManager;
- CGRect f=sc.statusBarFrame;
- h=f.size.height;
- }else{
- h=[UIApplication sharedApplication].statusBarFrame.size.height;
- }
- if(h>=40){
- h=30;
- }
- _customerbar =[[HomeCommonBarView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 72-20+h)];
- // _customerbar.bgView.backgroundColor = rgba(18, 23, 41, 1);
- // _customerbar.label.text=@"";
- // _customerbar.bgView.alpha = 0;
- // _customerbar.bgView.backgroundColor=[UIColor whiteColor];
- // _customerbar.label.text=@"管理图层排序";
- // _customerbar.label.textColor = rgba(255, 255, 255, 1);
- // [_customerbar.leftButton setImage:[UIImage imageNamed:@"his_back_w"] forState:UIControlStateNormal];
- // [_customerbar.rightButton setImage:[UIImage imageNamed:@"his_share_w"] forState:UIControlStateNormal];
- // [_customerbar.rightButton setTitleColor:RGBACOLOR(141, 146, 168, 1) forState:UIControlStateNormal];
- // _customerbar.rightButton.titleLabel.font =[UIFont systemFontOfSize:14];
- // [_customerbar.leftButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
- // [_customerbar.rightButton addTarget:self action:@selector(shareAction) forControlEvents:UIControlEventTouchUpInside];
-
- // [_customerbar.rightButton mas_remakeConstraints:^(MASConstraintMaker *make) {
- // make.centerY.equalTo(_customerbar.leftButton);
- // make.right.equalTo(_customerbar).offset(-15);
- // make.size.mas_equalTo(CGSizeMake(23, 23));
- // }];
- }
- return _customerbar;
- }
- @end
- #pragma mark -- homecell1
- @interface homecell1()
- @property(nonatomic,strong)UIScrollView *scrollView;
- @property(nonatomic,strong)NSTimer *mytimer;
- @end
- @implementation homecell1
- + (instancetype)cellWithTableView:(UITableView *)tableView{
- static NSString *identifier = @"homecell1";
- homecell1 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
- if (cell == nil) {
- cell = [[homecell1 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)setBanner:(NSArray *)banner{
- _banner = banner;
- _imageCount = (int)banner.count;
-
- [self.scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
- [self.scrollView removeFromSuperview];
- [self creatView];
-
- if(self.mytimer){
- [self.mytimer invalidate];
- self.mytimer = nil;
- }
- if(banner.count > 1){
- __weak typeof(self) weakSelf = self;
- self.mytimer = [NSTimer scheduledTimerWithTimeInterval:5.0 repeats:YES block:^(NSTimer * _Nonnull timer) {
- [weakSelf changeContentAct];
- }];
- [[NSRunLoop currentRunLoop ] addTimer:self.mytimer forMode:NSRunLoopCommonModes];
- }
-
- }
- -(void)changeContentAct{
- CGPoint x= self.scrollView.contentOffset;
- if(x.x >= kScreenWidth*(self.imageCount-1)){
- [self.scrollView setContentOffset:CGPointMake(0, x.y)];
- }else{
- [UIView animateWithDuration:0.3 animations:^{
- [self.scrollView setContentOffset:CGPointMake(x.x+kScreenWidth, x.y)];
- }];
- }
- }
- -(void)toplayAct:(UITapGestureRecognizer *)gest{
- int x = (int)gest.view.tag - 1000;
- __weak typeof (self) weakSelf = self;
- if(self.tapBlock){
- self.tapBlock([weakSelf.banner[x][@"vid"] intValue]);
- }
- }
- -(void)creatView{
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.backgroundColor = [UIColor clearColor];
- [self.contentView addSubview:self.scrollView];
- [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
- //375 340
- make.size.mas_equalTo(CGSizeMake(kScreenWidth, kScreenWidth*340/375));
- make.top.left.equalTo(self.contentView);
- }];
- self.scrollView.contentSize = CGSizeMake(kScreenWidth*self.imageCount, 0);
- for(int i=0;i<self.imageCount;i++){
- UIView *cview = [UIView new];
- cview.tag = 1000+i;
- UITapGestureRecognizer *toplayAct = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toplayAct:)];
- [cview addGestureRecognizer:toplayAct];
- // cview.backgroundColor =[UIColor grayColor];
- [self.scrollView addSubview:cview];
- [cview mas_makeConstraints:^(MASConstraintMaker *make) {
- //375 340
- make.size.mas_equalTo(CGSizeMake(kScreenWidth, kScreenWidth*340/375));
- make.top.equalTo(self.scrollView);
- make.left.equalTo(self.scrollView).offset(kScreenWidth*i);
- }];
-
- UIImageView *iview = [UIImageView new];
- iview.contentMode = UIViewContentModeScaleToFill;
- // iview.backgroundColor = [UIColor blueColor]; horizontal_cover_url vertical_cover_url
- [iview sd_setImageWithURL:[NSURL URLWithString:self.banner[i][@"horizontal_cover_url"]]];
- [cview addSubview:iview];
- [iview mas_makeConstraints:^(MASConstraintMaker *make) {
- //375 340
- make.size.mas_equalTo(CGSizeMake(kScreenWidth, kScreenWidth*340/375));
- make.center.equalTo(cview);
- }];
-
- UILabel *nameLabel = [UILabel new];
- nameLabel.font= [UIFont systemFontOfSize:36];
- nameLabel.textColor = [UIColor whiteColor];
- // nameLabel.text = self.banner[i][@"ch_name"];
- [cview addSubview:nameLabel];
- [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(cview).offset(16);
- make.top.equalTo(cview).offset(207);
- }];
-
- UIImageView *bimageview = [UIImageView new];
- bimageview.image = [UIImage imageNamed:@"Rectangle 57"];
- [cview addSubview:bimageview];
- [bimageview mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(cview).offset(256);
- make.right.left.bottom.equalTo(cview);
- }];
-
- UILabel *contentLabel = [UILabel new];
- contentLabel.font= [UIFont systemFontOfSize:14];
- contentLabel.textColor = rgba(255, 255, 255, 0.6);
- // contentLabel.text = self.banner[i][@"simple_detail"];
- [cview addSubview:contentLabel];
- [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(cview).offset(16);
- make.top.equalTo(cview).offset(256);
- }];
-
- CTPageControl *pc = [CTPageControl new];
- pc.numberOfPages = self.imageCount;
- pc.currentPage = i;
- pc.pageIndicatorTintColor = rgba(255, 255, 255, 0.6);
- pc.currentPageIndicatorTintColor = rgba(255, 186, 0, 1);
- [cview addSubview:pc];
- [pc mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(cview).offset(-15);
- make.bottom.equalTo(cview).offset(-24);
- }];
-
- UIImageView *playView= [UIImageView new];
- playView.image = [UIImage imageNamed:@"Group 3"];
- [cview addSubview:playView];
- [playView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(48, 48));
- make.right.equalTo(cview).offset(-16);
- make.top.equalTo(cview).offset(244);
- }];
- }
- }
- -(UIScrollView *)scrollView{
- if(!_scrollView){
- _scrollView = [[UIScrollView alloc] init];
- _scrollView.pagingEnabled = true;
- _scrollView.showsVerticalScrollIndicator = false;
- _scrollView.showsHorizontalScrollIndicator = false;
- }
- return _scrollView;
- }
- @end
- #pragma mark -- homecell2
- @interface homecell2()
- @property(nonatomic,strong)UIScrollView *scrollView;
- @end
- @implementation homecell2
- + (instancetype)cellWithTableView:(UITableView *)tableView{
- static NSString *identifier = @"homecell2";
- homecell2 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
- if (cell == nil) {
- cell = [[homecell2 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)setHotmovies:(NSArray *)hotmovies{
- _hotmovies = hotmovies;
- [self.scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
- [self.scrollView removeFromSuperview];
- [self creatView];
- }
- -(void)tapAct:(UITapGestureRecognizer *)g{
- NSInteger x = g.view.tag - 1000;
- int vid = [self.hotmovies[x][@"vid"] intValue];
- if(self.tapBlock){
- self.tapBlock(vid);
- }
- }
- -(void)addcollectAct:(UITapGestureRecognizer *)g{
- UIImageView *lefttop = (UIImageView *)g.view;
- NSInteger x = g.view.tag - 150;
- int vid = [self.hotmovies[x][@"vid"] intValue];
-
- if([UserModel collectContainVid:vid]){
- // [UserModel delCollect:self.hotmovies[x]];
- // lefttop.image = [UIImage imageNamed:@"Frame"];
- }else{
- [UserModel addCollect:self.hotmovies[x]];
- // lefttop.image = [UIImage imageNamed:@"Frame13"];
- lefttop.hidden = true;
- if(self.addCollectBlock){
- self.addCollectBlock();
- }
- }
- }
- -(void)creatView{
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.backgroundColor = [UIColor clearColor];
- [self.contentView addSubview:self.scrollView];
- [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(kScreenWidth, 268));
- make.top.left.equalTo(self.contentView);
- }];
-
- if(self.hotmovies.count<2){
- self.scrollView.contentSize = CGSizeMake(0, 0);
- }else if(self.hotmovies.count<4){
- self.scrollView.contentSize = CGSizeMake(634-8 - 208 , 0);
- }else{
- self.scrollView.contentSize = CGSizeMake(634-8, 0);
- }
-
- // UIImageView * hv= [UIImageView new];
- // [self.contentView addSubview:hv];
- // [hv mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.size.mas_equalTo(CGSizeMake(185, 268));
- // make.top.equalTo(self.contentView);
- // make.left.equalTo(self.scrollView).offset(12);
- // }];
-
- for(int i=0;i<self.hotmovies.count;i++){
- UIImageView * hvx= [UIImageView new];
- // hvx.backgroundColor = [UIColor redColor];
- if(i==0){
- [hvx sd_setImageWithURL:[NSURL URLWithString:self.hotmovies[i][@"vertical_cover_url"]]];
- }else{
- [hvx sd_setImageWithURL:[NSURL URLWithString:self.hotmovies[i][@"horizontal_cover_url"]]];
- }
- [self.scrollView addSubview:hvx];
- hvx.tag = 1000+i;
- hvx.userInteractionEnabled = true;
- UITapGestureRecognizer *g = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAct:)];
- [hvx addGestureRecognizer:g];
- if(i==0){
- [hvx mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(185, 268));
- make.top.equalTo(self.scrollView);
- make.left.equalTo(self.scrollView).offset(12);
- }];
- }else{
- [hvx mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(200, 130));
- if(i==3 || i==4){
- make.left.equalTo(self.scrollView).offset(205+8+200);
- }else{
- make.left.equalTo(self.scrollView).offset(205);
- }
- if(i==1 || i==3){
- make.top.equalTo(self.scrollView);
- }else{
- make.top.equalTo(self.scrollView).offset(138);
- }
-
- }];
- }
- UIImageView *lefttop = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
- if([UserModel collectContainVid:[self.hotmovies[i][@"vid"] intValue]]){
- // lefttop.image = [UIImage imageNamed:@"Frame13"];
- lefttop.hidden = true;
- }else{
- lefttop.image = [UIImage imageNamed:@"Frame"];
- lefttop.hidden = false;
- }
- lefttop.backgroundColor = rgba(19, 24, 42, 0.2);
- // 创建圆角路径
- UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:lefttop.bounds byRoundingCorners:UIRectCornerBottomRight cornerRadii:CGSizeMake(8, 8)];
- // 创建圆角图层
- CAShapeLayer *maskLayer = [CAShapeLayer layer];
- maskLayer.path = path.CGPath;
- lefttop.layer.mask = maskLayer;
-
- [hvx addSubview:lefttop];
- lefttop.tag = 150+i;
- lefttop.userInteractionEnabled = true;
- UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addcollectAct:)];
- [lefttop addGestureRecognizer:gest];
- [lefttop mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(24, 24));
- make.top.left.equalTo(hvx);
- }];
-
- UIImageView *righttop = [UIImageView new];
- righttop.image = [UIImage imageNamed:@"Rectangle 83"];
- [hvx addSubview:righttop];
- [righttop mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(40, 24));
- make.top.right.equalTo(hvx);
- }];
-
- UILabel *righttopText = [UILabel new];
- righttopText.font= [UIFont systemFontOfSize:14];
- righttopText.textColor = [UIColor whiteColor];
- righttopText.text = @"热门";
- [righttop addSubview:righttopText];
- [righttopText mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.equalTo(righttop);
- }];
-
- UIImageView *bottom = [UIImageView new];
- bottom.image = [UIImage imageNamed:@"Rectangle 57"];
- [hvx addSubview:bottom];
- [bottom mas_makeConstraints:^(MASConstraintMaker *make) {
- if(i==0){
- make.size.mas_equalTo(CGSizeMake(185, 64));
- }else{
- make.size.mas_equalTo(CGSizeMake(200, 50));
- }
- make.bottom.left.equalTo(hvx);
- }];
-
- UILabel *nameLabel = [UILabel new];
- nameLabel.font= [UIFont systemFontOfSize:14];
- nameLabel.textColor = [UIColor whiteColor];
- nameLabel.text = self.hotmovies[i][@"ch_name"];
- [bottom addSubview:nameLabel];
- [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(bottom).offset(8);
- if(i==0){
- make.top.equalTo(bottom).offset(20);
- }else{
- make.top.equalTo(bottom).offset(4);
- }
- }];
-
- UILabel *contentLabel = [UILabel new];
- contentLabel.font= [UIFont systemFontOfSize:12];
- contentLabel.textColor = rgba(255, 255, 255, 0.4);
- contentLabel.text = self.hotmovies[i][@"simple_detail"] ;
- [bottom addSubview:contentLabel];
- [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(bottom).offset(8);
- make.top.equalTo(nameLabel.mas_bottom);
- }];
-
- UILabel *scoreLabel = [UILabel new];
- scoreLabel.font= [UIFont boldSystemFontOfSize:16];
- scoreLabel.textColor = rgba(239, 164, 0, 1);
- scoreLabel.text = [NSString stringWithFormat:@"%.1f",[self.hotmovies[i][@"score"] floatValue]];
- [bottom addSubview:scoreLabel];
- [scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(bottom).offset(-10);
- make.centerY.equalTo(contentLabel.mas_top);
- }];
-
- hvx.layer.cornerRadius = 8;
- hvx.layer.masksToBounds = YES;
- hvx.layer.shadowColor = [UIColor colorWithRed:0.05 green:0.086 blue:0.142 alpha:0.6].CGColor;
- hvx.layer.shadowOffset = CGSizeMake(0, 4);
- hvx.layer.shadowOpacity = 1;
- hvx.layer.shadowRadius = 20;
- }
- }
- -(UIScrollView *)scrollView{
- if(!_scrollView){
- _scrollView = [[UIScrollView alloc] init];
- _scrollView.pagingEnabled = true;
- _scrollView.showsVerticalScrollIndicator = false;
- _scrollView.showsHorizontalScrollIndicator = false;
- }
- return _scrollView;
- }
- @end
- #pragma mark -- homecell3
- @implementation homecell3
- + (instancetype)cellWithTableView:(UITableView *)tableView{
- static NSString *identifier = @"homecell3";
- homecell3 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
- if (cell == nil) {
- cell = [[homecell3 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)setTodayCommond:(NSArray *)todayCommond{
- _todayCommond = todayCommond;
- for(int i=0;i<3;i++){
- if(i<todayCommond.count){
- [self.contentView viewWithTag:1000+i].hidden = false;
- UIView *cview = [self.contentView viewWithTag:1000+i ];
- UIImageView *iv =[cview viewWithTag:100+i];
- [iv sd_setImageWithURL:[NSURL URLWithString:todayCommond[i][@"vertical_cover_url"]]];
-
- UILabel *lab =[cview viewWithTag:200+i];
- lab.text = [NSString stringWithFormat:@"%.1f",[todayCommond[i][@"score"] floatValue]];
-
- UILabel *lab2 =[cview viewWithTag:300+i];
- lab2.text = todayCommond[i][@"ch_name"];
-
- UILabel *lab3 =[cview viewWithTag:400+i];
- lab3.text = todayCommond[i][@"simple_detail"];
-
- UIImageView *lefttop=[iv viewWithTag:150+i];
- if([UserModel collectContainVid:[todayCommond[i][@"vid"] intValue]]){
- // lefttop.image = [UIImage imageNamed:@"Frame13"];
- lefttop.hidden = true;
- }else{
- lefttop.image = [UIImage imageNamed:@"Frame"];
- lefttop.hidden = false;
- }
-
- }else{
- [self.contentView viewWithTag:1000+i ].hidden = true;
- }
- }
-
- }
- -(void)Act:(UITapGestureRecognizer *)g{
- NSInteger x= g.view.tag - 1000;
- int vid = [self.todayCommond[x][@"vid"] intValue];
- if(self.tapBlock){
- self.tapBlock(vid);
- }
- }
- -(void)addcollectAct:(UITapGestureRecognizer *)g{
- NSInteger x= g.view.tag - 150;
- int vid = [self.todayCommond[x][@"vid"] intValue];
-
- UIImageView *lefttop = (UIImageView *)g.view;
- if([UserModel collectContainVid:vid]){
- // [UserModel delCollect:self.todayCommond[x]];
- // lefttop.image = [UIImage imageNamed:@"Frame"];
- }else{
- [UserModel addCollect:self.todayCommond[x]];
- // lefttop.image = [UIImage imageNamed:@"Frame13"];
- lefttop.hidden = true;
- if(self.addCollectBlock){
- self.addCollectBlock();
- }
- }
- }
- -(void)creatView{
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- CGFloat m = (kScreenWidth - 3*112 - 24)/2;
- self.backgroundColor = [UIColor clearColor];
- for(int i=0;i<3;i++){
- UIView *cview =[UIView new];
- [self.contentView addSubview:cview];
- cview.tag = 1000+i;
- UITapGestureRecognizer *g=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Act:)];
- [cview addGestureRecognizer:g];
- [cview mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(112, 214));
- if(i==0){
- make.left.equalTo(self.contentView).offset(12);
- }else{
- make.left.equalTo(self.contentView).offset(12+(m+112)*i);
- }
- make.top.equalTo(self.contentView);
- }];
-
- UIImageView *imagev =[UIImageView new];
- imagev.tag = 100+i;
- imagev.image = [UIImage imageNamed:@"Rectangle 16"];
- [cview addSubview:imagev];
- [imagev mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(112, 146));
- make.left.equalTo(cview);
- make.top.equalTo(cview);
- }];
-
- UIImageView *lefttop = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
- lefttop.image = [UIImage imageNamed:@"Frame"];
- [imagev addSubview:lefttop];
- lefttop.tag = 150+i;
- lefttop.userInteractionEnabled = true;
- UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addcollectAct:)];
- [lefttop addGestureRecognizer:gest];
- [lefttop mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(24, 24));
- make.top.left.equalTo(imagev);
- }];
-
- lefttop.backgroundColor = rgba(19, 24, 42, 0.2);
- // 创建圆角路径
- UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:lefttop.bounds byRoundingCorners:UIRectCornerBottomRight cornerRadii:CGSizeMake(8, 8)];
- // 创建圆角图层
- CAShapeLayer *maskLayer = [CAShapeLayer layer];
- maskLayer.path = path.CGPath;
- lefttop.layer.mask = maskLayer;
-
- UIImageView *bimageview = [UIImageView new];
- bimageview.image = [UIImage imageNamed:@"Rectangle 57"];
- [imagev addSubview:bimageview];
- [bimageview mas_makeConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(@35);
- make.bottom.left.right.equalTo(imagev);
- }];
-
- UILabel *scoreLabel = [UILabel new];
- scoreLabel.tag = 200+i;
- scoreLabel.font= [UIFont boldSystemFontOfSize:16];
- scoreLabel.textColor = rgba(239, 164, 0, 1);
- scoreLabel.text = @"9.4";
- [imagev addSubview:scoreLabel];
- [scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(imagev).offset(-8);
- make.bottom.equalTo(imagev).offset(-6);
- }];
-
-
- UILabel *nameLabel = [UILabel new];
- nameLabel.tag = 300+i;
- nameLabel.font= [UIFont systemFontOfSize:14];
- nameLabel.textColor = [UIColor whiteColor];
- nameLabel.text = @"你的名字";
- [cview addSubview:nameLabel];
- [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(cview);
- make.top.equalTo(imagev.mas_bottom).offset(8);
- }];
-
- UILabel *contentLabel = [UILabel new];
- contentLabel.tag = 400+i;
- contentLabel.font= [UIFont systemFontOfSize:12];
- contentLabel.textColor = rgba(255, 255, 255, 0.4);
- contentLabel.text = @"你的名字详情";
- [cview addSubview:contentLabel];
- [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(cview);
- make.top.equalTo(nameLabel.mas_bottom);
- }];
-
-
- cview.layer.cornerRadius = 8;
- cview.layer.masksToBounds = YES;
- // imagev.layer.shadowColor = [UIColor colorWithRed:0.05 green:0.086 blue:0.142 alpha:0.6].CGColor;
- // imagev.layer.shadowOffset = CGSizeMake(0, 4);
- // imagev.layer.shadowOpacity = 1;
- // imagev.layer.shadowRadius = 20;
- }
- }
- @end
- #pragma mark -- headerView
- @interface headerView()
- @property(nonatomic,strong)UILabel *hl;
- @end
- @implementation headerView
- - (instancetype)init
- {
- self = [super init];
- if (self) {
- [self initView];
- }
- return self;
- }
- -(void)setTitle:(NSString *)title{
- _title = title;
- self.hl.text = title;
- }
- - (void)initView{
- self.hl = [UILabel new];
- self.hl.text = @"热门影视";
- self.hl.font = [UIFont boldSystemFontOfSize:16];
- self.hl.textColor =[UIColor whiteColor];
- self.hl.textAlignment = NSTextAlignmentLeft;
- [self addSubview:self.hl];
- [self.hl mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self).offset(12);
- make.top.right.bottom.equalTo(self);
- }];
- }
- @end
- #pragma mark -- home2cell1
- @interface home2cell1()
- @property(nonatomic,strong)UIScrollView *scrollView;
- @end
- @implementation home2cell1
- + (instancetype)cellWithTableView:(UITableView *)tableView{
- static NSString *identifier = @"home2cell1";
- home2cell1 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
- if (cell == nil) {
- cell = [[home2cell1 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)setTopCommondData:(NSArray *)topCommondData{
- _topCommondData = topCommondData;
- self.imageCount = (int)topCommondData.count;
- }
- -(void)setImageCount:(int)imageCount{
- _imageCount = imageCount;
-
- [self.scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
- [self.scrollView removeFromSuperview];
- [self creatView];
- }
- -(void)Act:(UITapGestureRecognizer *)g{
- NSInteger x= g.view.tag -1000;
- int vid = [self.topCommondData[x][@"vid"] intValue];
- if(self.tapBlock){
- self.tapBlock(vid);
- }
- }
- -(void)addcollectAct:(UITapGestureRecognizer *)g{
- NSInteger x= g.view.tag -150;
- int vid = [self.topCommondData[x][@"vid"] intValue];
- UIImageView *lefttop = (UIImageView *)g.view;
- if([UserModel collectContainVid:vid]){
- // [UserModel delCollect:self.topCommondData[x]];
- // lefttop.image = [UIImage imageNamed:@"Frame"];
- }else{
- [UserModel addCollect:self.topCommondData[x]];
- // lefttop.image = [UIImage imageNamed:@"Frame13"];
- lefttop.hidden = true;
- if(self.addCollectBlock){
- self.addCollectBlock();
- }
- }
- }
- -(void)creatView{
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.backgroundColor = [UIColor clearColor];
- [self.contentView addSubview:self.scrollView];
- [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(kScreenWidth, 330));
- make.top.left.equalTo(self.contentView);
- }];
- self.scrollView.contentSize = CGSizeMake(24+(self.imageCount-1)*8 +self.imageCount*230 , 0);
- for(int i=0;i<self.imageCount;i++){
- UIView *cview = [UIView new];
- // cview.backgroundColor =[UIColor grayColor];
- [self.scrollView addSubview:cview];
- cview.tag = 1000+i;
- UITapGestureRecognizer *g=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Act:)];
- [cview addGestureRecognizer:g];
- [cview mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(230, 330));
- make.top.equalTo(self.scrollView);
- make.left.equalTo(self.scrollView).offset(12+(230+8)*i);
- }];
-
- UIImageView *iview = [UIImageView new];
- // iview.backgroundColor = [UIColor blueColor];
- [iview sd_setImageWithURL:[NSURL URLWithString:self.topCommondData[i][@"vertical_cover_url"]]];
- [cview addSubview:iview];
- [iview mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(230, 330));
- make.center.equalTo(cview);
- }];
-
- UIImageView *lefttop = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
- if([UserModel collectContainVid:[self.topCommondData[i][@"vid"] intValue]]){
- // lefttop.image = [UIImage imageNamed:@"Frame13"];
- lefttop.hidden = true;
- }else{
- lefttop.image = [UIImage imageNamed:@"Frame"];
- lefttop.hidden = false;
- }
-
- lefttop.backgroundColor = rgba(19, 24, 42, 0.2);
- // 创建圆角路径
- UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:lefttop.bounds byRoundingCorners:UIRectCornerBottomRight cornerRadii:CGSizeMake(8, 8)];
- // 创建圆角图层
- CAShapeLayer *maskLayer = [CAShapeLayer layer];
- maskLayer.path = path.CGPath;
- lefttop.layer.mask = maskLayer;
-
- // lefttop.image = [UIImage imageNamed:@"Frame"];
- [cview addSubview:lefttop];
- lefttop.tag = 150+i;
- lefttop.userInteractionEnabled = true;
- UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addcollectAct:)];
- [lefttop addGestureRecognizer:gest];
- [lefttop mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(16, 16));
- make.top.left.equalTo(cview);
- }];
-
- UIImageView *bimageview = [UIImageView new];
- bimageview.image = [UIImage imageNamed:@"Rectangle 57"];
- [cview addSubview:bimageview];
- [bimageview mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(230, 68));
- make.right.bottom.equalTo(cview);
- }];
-
- UILabel *nameLabel = [UILabel new];
- nameLabel.font= [UIFont systemFontOfSize:14];
- nameLabel.textColor = [UIColor whiteColor];
- nameLabel.text = self.topCommondData[i][@"ch_name"];
- [bimageview addSubview:nameLabel];
- [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(bimageview).offset(8);
- make.top.equalTo(bimageview).offset(24);
- }];
-
- UILabel *contentLabel = [UILabel new];
- contentLabel.font= [UIFont systemFontOfSize:12];
- contentLabel.textColor = rgba(255, 255, 255, 0.4);
- contentLabel.text = self.topCommondData[i][@"simple_detail"];
- [bimageview addSubview:contentLabel];
- [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(nameLabel);
- make.top.equalTo(nameLabel.mas_bottom);
- }];
-
-
- UILabel *scoreLabel = [UILabel new];
- scoreLabel.font= [UIFont boldSystemFontOfSize:16];
- scoreLabel.textColor = rgba(239, 164, 0, 1);
- scoreLabel.text = [NSString stringWithFormat:@"%.1f",[self.topCommondData[i][@"score"] floatValue]];
- [bimageview addSubview:scoreLabel];
- [scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(bimageview).offset(-12);
- make.bottom.equalTo(bimageview).offset(-6);
- }];
-
-
- cview.layer.cornerRadius = 8;
- cview.layer.masksToBounds = YES;
- }
-
- }
- -(UIScrollView *)scrollView{
- if(!_scrollView){
- _scrollView = [[UIScrollView alloc] init];
- // _scrollView.pagingEnabled = true;
- _scrollView.showsVerticalScrollIndicator = false;
- _scrollView.showsHorizontalScrollIndicator = false;
- }
- return _scrollView;
- }
- @end
- #pragma mark -- home2cell2
- @interface home2cell2()
- @property(nonatomic,strong)UIView *cview;
- @end
- @implementation home2cell2
- + (instancetype)cellWithTableView:(UITableView *)tableView{
- static NSString *identifier = @"home2cell2";
- home2cell2 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
- if (cell == nil) {
- cell = [[home2cell2 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;
- }
- -(UIView *)cview{
- if(!_cview){
- _cview =[UIView new];
- }
- return _cview;
- }
- -(void)setObj:(NSDictionary *)obj{
- _obj = obj;
- UIImageView * hvx = [self.cview viewWithTag:100];
- [hvx sd_setImageWithURL:[NSURL URLWithString:obj[@"horizontal_cover_url"]]];
-
- UIImageView *icon = [[self.cview viewWithTag:200] viewWithTag:101];
- [icon sd_setImageWithURL:[NSURL URLWithString:obj[@"vertical_cover_url"]]];
-
- UILabel *lab1 = [[self.cview viewWithTag:200] viewWithTag:102];
- lab1.text = obj[@"ch_name"];
-
- UILabel *lab2 = [[self.cview viewWithTag:200] viewWithTag:103];
- lab2.text = obj[@"simple_detail"];
-
- UILabel *lab3 = [[self.cview viewWithTag:200] viewWithTag:104];
- lab3.text = obj[@"simple_detail"];
-
- UILabel *lab4 = [[self.cview viewWithTag:200] viewWithTag:105];
- lab4.text = [NSString stringWithFormat:@"%.1f",[obj[@"score"] floatValue]];
-
- UIImageView *lefttop = [self.cview viewWithTag:150];
- if([UserModel collectContainVid:[obj[@"vid"] intValue]]){
- // lefttop.image = [UIImage imageNamed:@"Frame13"];
- lefttop.hidden = true;
- }else{
- lefttop.image = [UIImage imageNamed:@"Frame"];
- lefttop.hidden = false;
- }
- }
- -(void)Act:(UITapGestureRecognizer *)g{
- int vid = [self.obj[@"vid"] intValue];
- if(self.tapBlock){
- self.tapBlock(vid);
- }
- }
- -(void)addcollectAct:(UITapGestureRecognizer *)g{
- int vid = [self.obj[@"vid"] intValue];
- UIImageView *lefttop = (UIImageView *)g.view;
- if([UserModel collectContainVid:vid]){
- // [UserModel delCollect:self.obj];
- // lefttop.image = [UIImage imageNamed:@"Frame"];
- }else{
- [UserModel addCollect:self.obj];
- // lefttop.image = [UIImage imageNamed:@"Frame13"];
- lefttop.hidden = true;
- if(self.addCollectBlock){
- self.addCollectBlock();
- }
- }
- }
- -(void)creatView{
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.backgroundColor = [UIColor clearColor];
- [self.contentView addSubview:self.cview];
- [self.cview mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-24, 272));
- make.top.equalTo(self.contentView);
- make.left.equalTo(self.contentView).offset(12);
- }];
- UITapGestureRecognizer *g=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Act:)];
- [self.cview addGestureRecognizer:g];
-
- UIImageView * hvx= [UIImageView new];
- // hvx.backgroundColor = [UIColor redColor];
- hvx.tag=100;
- [self.cview addSubview:hvx];
-
- [hvx mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.cview);
- }];
-
- UIImageView *lefttop = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
- lefttop.image = [UIImage imageNamed:@"Frame"];
- [self.cview addSubview:lefttop];
- lefttop.tag = 150;
- lefttop.userInteractionEnabled = true;
- UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addcollectAct:)];
- [lefttop addGestureRecognizer:gest];
- [lefttop mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(24, 24));
- make.top.left.equalTo(self.cview );
- }];
-
- lefttop.backgroundColor = rgba(19, 24, 42, 0.2);
- // 创建圆角路径
- UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:lefttop.bounds byRoundingCorners:UIRectCornerBottomRight cornerRadii:CGSizeMake(8, 8)];
- // 创建圆角图层
- CAShapeLayer *maskLayer = [CAShapeLayer layer];
- maskLayer.path = path.CGPath;
- lefttop.layer.mask = maskLayer;
-
- UIView *bottomV = [UIView new];
- bottomV.tag = 200;
- bottomV.backgroundColor = rgba(30, 46, 63, 1);
- [self.cview addSubview:bottomV];
- [bottomV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(@75);
- make.bottom.left.right.equalTo(self.cview);
- }];
-
- UIImageView *icon = [UIImageView new];
- // icon.image = [UIImage imageNamed:@"Rectangle 83"];
- icon.tag = 101;
- // icon.backgroundColor = [UIColor darkGrayColor];
- [bottomV addSubview:icon];
- [icon mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(45, 59));
- make.top.equalTo(bottomV).offset(8);
- make.left.equalTo(bottomV).offset(8);
- }];
-
-
-
- UILabel *nameLabel = [UILabel new];
- nameLabel.font= [UIFont systemFontOfSize:14];
- nameLabel.textColor = [UIColor whiteColor];
- nameLabel.tag = 102;
- nameLabel.text = @"你的名字";
- [bottomV addSubview:nameLabel];
- [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(icon.mas_right).offset(8);
- make.top.equalTo(icon);
- }];
-
- UILabel *contentLabel = [UILabel new];
- contentLabel.font= [UIFont systemFontOfSize:12];
- contentLabel.textColor = rgba(255, 255, 255, 0.4);
- contentLabel.tag = 103;
- contentLabel.text = @"你的名字详情";
- [bottomV addSubview:contentLabel];
- [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(nameLabel);
- // make.top.equalTo(nameLabel.mas_bottom);
- make.centerY.equalTo(icon);
- }];
-
- UILabel *styleLabel = [UILabel new];
- styleLabel.font= [UIFont systemFontOfSize:12];
- styleLabel.textColor = rgba(255, 255, 255, 0.4);
- styleLabel.text = @"奥斯卡获奖佳片";
- styleLabel.tag = 104;
- [bottomV addSubview:styleLabel];
- [styleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(nameLabel);
- make.bottom.equalTo(icon);
- }];
-
- UILabel *scoreLabel = [UILabel new];
- scoreLabel.font= [UIFont boldSystemFontOfSize:18];
- scoreLabel.textColor = rgba(239, 164, 0, 1);
- scoreLabel.text = @"9.4";
- scoreLabel.tag = 105;
- [bottomV addSubview:scoreLabel];
- [scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(bottomV).offset(-8);
- make.bottom.equalTo(bottomV).offset(-8);
- }];
-
- icon.layer.cornerRadius = 6;
- icon.layer.masksToBounds = YES;
- self.cview.layer.cornerRadius = 8;
- self.cview.layer.masksToBounds = YES;
- // hvx.layer.shadowColor = [UIColor colorWithRed:0.05 green:0.086 blue:0.142 alpha:0.6].CGColor;
- // hvx.layer.shadowOffset = CGSizeMake(0, 4);
- // hvx.layer.shadowOpacity = 1;
- // hvx.layer.shadowRadius = 20;
- }
- @end
|