ViewController.m 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  1. //
  2. // ViewController.m
  3. // chinaTV
  4. //
  5. // Created by 刘伟伟 on 2023/7/5.
  6. //
  7. #import "ViewController.h"
  8. #import "HomeCommonBarView.h"
  9. #import "CTPageControl.h"
  10. #import "ZFNormalViewController.h"
  11. #import "SearchCommonBarView.h"
  12. #import "SearchResultViewController.h"
  13. #import <MJRefresh.h>
  14. @interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
  15. @property(nonatomic,strong)HomeCommonBarView *customerbar;
  16. @property(nonatomic,strong)SearchCommonBarView *homeSearchBar;
  17. @property(nonatomic,strong)UITableView *tableView;
  18. @property(nonatomic,strong)NSDictionary *homePageData;
  19. @property(nonatomic,strong)NSMutableArray *todayCommondData;
  20. @property(nonatomic,assign)int vid;
  21. @property(nonatomic,assign)int tb1footpage;
  22. @end
  23. @implementation ViewController
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. self.tb1footpage = 1;
  27. self.todayCommondData = [NSMutableArray array];
  28. [self setupUI];
  29. [self requestHomePageData];
  30. }
  31. -(void)requestHomePageData{
  32. if(![UserModel userToken]){
  33. [RequestTool post:@"user/userLogin" params:@{@"account":@"test",@"password":@"123456"} success:^(id responseObject) {
  34. NSLog(@"%@",responseObject);
  35. [[NSUserDefaults standardUserDefaults] setValue:responseObject[@"data"] forKey:@"existUserData"];
  36. [self requestHomePageData2];
  37. } failure:^(NSError *error) {
  38. NSLog(@"%@",error);
  39. }];
  40. }else{
  41. [self requestHomePageData2];
  42. }
  43. }
  44. -(void)todayReCommond{
  45. //今日推荐
  46. if(self.tb1footpage>10){
  47. [self.tableView.mj_footer endRefreshing];
  48. return;
  49. }
  50. [RequestTool post:@"home/dailyRecommend" params:@{@"page":@{@"page":@(self.tb1footpage),@"pageSize":@(9)}} success:^(id responseObject) {
  51. NSLog(@"home/dailyRecommend-%@",responseObject);
  52. if([responseObject[@"code"] intValue] == 0){
  53. NSArray *temp = responseObject[@"data"][@"list"];
  54. if(![temp isKindOfClass:[NSNull class]] && temp.count>0){
  55. [self.todayCommondData addObjectsFromArray:temp];
  56. // [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:2] withRowAnimation:UITableViewRowAnimationNone];
  57. [self.tableView reloadData];
  58. }
  59. [self.tableView.mj_footer endRefreshing];
  60. }
  61. } failure:^(NSError *error) {
  62. [self.tableView.mj_footer endRefreshing];
  63. }];
  64. }
  65. -(void)homeSearchWithKeyword:(NSString *)keyword{
  66. NSString *trimmed = [[keyword stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] copy];
  67. if(trimmed.length == 0){
  68. return;
  69. }
  70. [self.view endEditing:YES];
  71. NSMutableArray *history = [NSMutableArray array];
  72. id storedHistory = [[NSUserDefaults standardUserDefaults] objectForKey:@"mylocationhistory"];
  73. if([storedHistory isKindOfClass:[NSArray class]]){
  74. [history addObjectsFromArray:(NSArray *)storedHistory];
  75. }
  76. if(![history containsObject:trimmed]){
  77. [history addObject:trimmed];
  78. [[NSUserDefaults standardUserDefaults] setObject:history forKey:@"mylocationhistory"];
  79. }
  80. SearchResultViewController *vc = [SearchResultViewController new];
  81. vc.txt = trimmed;
  82. vc.hidesBottomBarWhenPushed = true;
  83. [self.navigationController pushViewController:vc animated:true];
  84. }
  85. -(void)requestHomePageData2{
  86. //首页数据
  87. [RequestTool post:@"home/homePage" params:@{} success:^(id responseObject) {
  88. NSLog(@"home/homePage-%@",responseObject);
  89. if([responseObject[@"code"] intValue] == 0){
  90. self.homePageData = responseObject[@"data"];
  91. [self.tableView reloadData];
  92. }
  93. } failure:^(NSError *error) {}];
  94. [self todayReCommond];
  95. // 推荐相关逻辑已移除
  96. }
  97. -(void)setupUI{
  98. self.fd_prefersNavigationBarHidden = true;
  99. [self.view addSubview:self.tableView];
  100. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  101. make.edges.equalTo(self.view);
  102. }];
  103. [self.tableView reloadData];
  104. [self.view addSubview:self.customerbar];
  105. [self.view bringSubviewToFront:self.customerbar];
  106. self.homeSearchBar.frame = self.customerbar.bounds;
  107. self.homeSearchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  108. [self.customerbar addSubview:self.homeSearchBar];
  109. __weak typeof (self) weakSelf = self;
  110. self.customerbar.changeTitAction = nil;
  111. self.customerbar.changeActionToFirst = ^{
  112. CGPoint point=weakSelf.tableView.contentOffset;
  113. if(point.y<100){
  114. weakSelf.customerbar.imageView.hidden = true;
  115. weakSelf.customerbar.bgView.backgroundColor = [UIColor clearColor];
  116. weakSelf.homeSearchBar.backgroundColor = [UIColor clearColor];
  117. }
  118. };
  119. }
  120. -(UIStatusBarStyle)preferredStatusBarStyle{
  121. return UIStatusBarStyleLightContent;
  122. }
  123. //监听scrollView滑动
  124. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  125. if (scrollView == self.tableView) {
  126. CGFloat offsetY = scrollView.contentOffset.y;
  127. // NSLog(@"%f",offsetY);
  128. if(offsetY > 100 && self.customerbar.imageView.isHidden){
  129. self.customerbar.imageView.hidden = false;
  130. self.customerbar.bgView.backgroundColor = rgba(18, 23, 41, 1);
  131. self.homeSearchBar.backgroundColor = rgba(18, 23, 41, 1);
  132. }
  133. if(offsetY<=100 && !self.customerbar.imageView.isHidden){
  134. self.customerbar.imageView.hidden = true;
  135. self.customerbar.bgView.backgroundColor = [UIColor clearColor];
  136. self.homeSearchBar.backgroundColor = [UIColor clearColor];
  137. }
  138. }
  139. }
  140. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  141. if(tableView == self.tableView){
  142. if(section == 0){
  143. return 0;
  144. }else{
  145. return 54;
  146. }
  147. }
  148. return 0;
  149. }
  150. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  151. return 0.01;
  152. }
  153. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  154. if(tableView == self.tableView){
  155. if(section == 1){
  156. headerView *header = [[headerView alloc] init];
  157. header.title = @"热门影视";
  158. return header;
  159. }else if(section == 2){
  160. headerView *header = [[headerView alloc] init];
  161. header.title = @"今日推荐";
  162. return header;
  163. }
  164. }
  165. return [UIView new];
  166. }
  167. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  168. if(tableView == self.tableView){
  169. return 3;
  170. }
  171. return 0;
  172. }
  173. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  174. if(tableView == self.tableView){
  175. if(section == 2){
  176. if(self.todayCommondData.count%3==0){
  177. return self.todayCommondData.count/3;
  178. }else{
  179. return self.todayCommondData.count/3 + 1;
  180. }
  181. }else{
  182. return 1;
  183. }
  184. }
  185. return 0;
  186. }
  187. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  188. if(tableView == self.tableView){
  189. if(indexPath.section == 0){
  190. return kScreenWidth*340/375;
  191. }else if(indexPath.section ==1){
  192. return 268;
  193. }else {
  194. return 214;
  195. }
  196. }
  197. return 0;
  198. }
  199. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  200. __weak typeof (self) weakSelf = self;
  201. if(tableView == self.tableView){
  202. if(indexPath.section == 0){
  203. homecell1 *cell = [homecell1 cellWithTableView:tableView];
  204. cell.banner = self.homePageData[@"banners"];
  205. cell.tapBlock = ^(int index) {
  206. weakSelf.vid = index;
  207. [weakSelf playItem];
  208. };
  209. return cell;
  210. }else if(indexPath.section == 1){
  211. homecell2 *cell = [homecell2 cellWithTableView:tableView];
  212. cell.hotmovies = self.homePageData[@"hot_movies"];
  213. cell.tapBlock = ^(int index) {
  214. weakSelf.vid = index;
  215. [weakSelf playItem];
  216. };
  217. return cell;
  218. }else{
  219. homecell3 *cell = [homecell3 cellWithTableView:tableView];
  220. if(indexPath.row*3 + 3>self.todayCommondData.count){
  221. cell.todayCommond = [self.todayCommondData subarrayWithRange:NSMakeRange(indexPath.row*3, self.todayCommondData.count-indexPath.row*3)];
  222. }else{
  223. cell.todayCommond = [self.todayCommondData subarrayWithRange:NSMakeRange(indexPath.row*3, 3)];
  224. }
  225. cell.tapBlock = ^(int index) {
  226. weakSelf.vid = index;
  227. [weakSelf playItem];
  228. };
  229. return cell;
  230. }
  231. }
  232. return nil;
  233. }
  234. -(void)playItem{
  235. ZFNormalViewController *vc = [[ZFNormalViewController alloc] init];
  236. vc.vid = self.vid;
  237. vc.hidesBottomBarWhenPushed = true;
  238. [self.navigationController pushViewController:vc animated:true];
  239. }
  240. -(UITableView *)tableView{
  241. if(!_tableView){
  242. _tableView =[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
  243. _tableView.delegate = self;
  244. _tableView.dataSource = self;
  245. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  246. _tableView.showsVerticalScrollIndicator = false;
  247. _tableView.showsHorizontalScrollIndicator = false;
  248. _tableView.backgroundColor = rgba(18, 23, 41, 1);
  249. __weak typeof(self) weakSelf = self;
  250. _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  251. weakSelf.tb1footpage += 1;
  252. [weakSelf todayReCommond];
  253. }];
  254. // _tableView.backgroundColor = [UIColor redColor];
  255. if (@available(iOS 11, *)) {
  256. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  257. _tableView.estimatedRowHeight = 0;
  258. _tableView.estimatedSectionFooterHeight = 0;
  259. _tableView.estimatedSectionHeaderHeight = 0;
  260. UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
  261. UIEdgeInsets safeAreaInsets = keyWindow.safeAreaInsets;
  262. CGFloat topSafeArea = safeAreaInsets.top;
  263. _tableView.contentInset = UIEdgeInsetsMake(iphoneX ? -topSafeArea : -35 , 0, BAR_HEIGHT, 0);
  264. }
  265. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 // only Xcode 13+ needs and can compile this
  266. if (@available(iOS 15.0, *)) {
  267. _tableView.sectionHeaderTopPadding = 0;
  268. }
  269. #endif
  270. }
  271. return _tableView;
  272. }
  273. -(SearchCommonBarView *)homeSearchBar{
  274. if(!_homeSearchBar){
  275. _homeSearchBar = [[SearchCommonBarView alloc] initWithFrame:CGRectZero];
  276. _homeSearchBar.backgroundColor = [UIColor clearColor];
  277. __weak typeof(self) weakSelf = self;
  278. _homeSearchBar.searchAction = ^(NSString * _Nonnull tit) {
  279. [weakSelf homeSearchWithKeyword:tit];
  280. };
  281. }
  282. return _homeSearchBar;
  283. }
  284. -(HomeCommonBarView *)customerbar{
  285. if(!_customerbar){
  286. CGFloat h=0;
  287. if(@available(iOS 13.0, *)){
  288. UIStatusBarManager *sc= [UIApplication sharedApplication].windows.firstObject.windowScene.statusBarManager;
  289. CGRect f=sc.statusBarFrame;
  290. h=f.size.height;
  291. }else{
  292. h=[UIApplication sharedApplication].statusBarFrame.size.height;
  293. }
  294. if(h>=40){
  295. h=30;
  296. }
  297. _customerbar =[[HomeCommonBarView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 72-20+h)];
  298. // _customerbar.bgView.backgroundColor = rgba(18, 23, 41, 1);
  299. // _customerbar.label.text=@"";
  300. // _customerbar.bgView.alpha = 0;
  301. // _customerbar.bgView.backgroundColor=[UIColor whiteColor];
  302. // _customerbar.label.text=@"管理图层排序";
  303. // _customerbar.label.textColor = rgba(255, 255, 255, 1);
  304. // [_customerbar.leftButton setImage:[UIImage imageNamed:@"his_back_w"] forState:UIControlStateNormal];
  305. // [_customerbar.rightButton setImage:[UIImage imageNamed:@"his_share_w"] forState:UIControlStateNormal];
  306. // [_customerbar.rightButton setTitleColor:RGBACOLOR(141, 146, 168, 1) forState:UIControlStateNormal];
  307. // _customerbar.rightButton.titleLabel.font =[UIFont systemFontOfSize:14];
  308. // [_customerbar.leftButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  309. // [_customerbar.rightButton addTarget:self action:@selector(shareAction) forControlEvents:UIControlEventTouchUpInside];
  310. // [_customerbar.rightButton mas_remakeConstraints:^(MASConstraintMaker *make) {
  311. // make.centerY.equalTo(_customerbar.leftButton);
  312. // make.right.equalTo(_customerbar).offset(-15);
  313. // make.size.mas_equalTo(CGSizeMake(23, 23));
  314. // }];
  315. }
  316. return _customerbar;
  317. }
  318. @end
  319. #pragma mark -- homecell1
  320. @interface homecell1()
  321. @property(nonatomic,strong)UIScrollView *scrollView;
  322. @property(nonatomic,strong)NSTimer *mytimer;
  323. @end
  324. @implementation homecell1
  325. + (instancetype)cellWithTableView:(UITableView *)tableView{
  326. static NSString *identifier = @"homecell1";
  327. homecell1 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  328. if (cell == nil) {
  329. cell = [[homecell1 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  330. }
  331. return cell;
  332. }
  333. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  334. {
  335. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  336. if (self) {
  337. // [self creatView];
  338. }
  339. return self;
  340. }
  341. -(void)setBanner:(NSArray *)banner{
  342. _banner = banner;
  343. _imageCount = (int)banner.count;
  344. [self.scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  345. [self.scrollView removeFromSuperview];
  346. [self creatView];
  347. if(self.mytimer){
  348. [self.mytimer invalidate];
  349. self.mytimer = nil;
  350. }
  351. if(banner.count > 1){
  352. __weak typeof(self) weakSelf = self;
  353. self.mytimer = [NSTimer scheduledTimerWithTimeInterval:5.0 repeats:YES block:^(NSTimer * _Nonnull timer) {
  354. [weakSelf changeContentAct];
  355. }];
  356. [[NSRunLoop currentRunLoop ] addTimer:self.mytimer forMode:NSRunLoopCommonModes];
  357. }
  358. }
  359. -(void)changeContentAct{
  360. CGPoint x= self.scrollView.contentOffset;
  361. if(x.x >= kScreenWidth*(self.imageCount-1)){
  362. [self.scrollView setContentOffset:CGPointMake(0, x.y)];
  363. }else{
  364. [UIView animateWithDuration:0.3 animations:^{
  365. [self.scrollView setContentOffset:CGPointMake(x.x+kScreenWidth, x.y)];
  366. }];
  367. }
  368. }
  369. -(void)toplayAct:(UITapGestureRecognizer *)gest{
  370. int x = (int)gest.view.tag - 1000;
  371. __weak typeof (self) weakSelf = self;
  372. if(self.tapBlock){
  373. self.tapBlock([weakSelf.banner[x][@"vid"] intValue]);
  374. }
  375. }
  376. -(void)creatView{
  377. self.selectionStyle = UITableViewCellSelectionStyleNone;
  378. self.backgroundColor = [UIColor clearColor];
  379. [self.contentView addSubview:self.scrollView];
  380. [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  381. //375 340
  382. make.size.mas_equalTo(CGSizeMake(kScreenWidth, kScreenWidth*340/375));
  383. make.top.left.equalTo(self.contentView);
  384. }];
  385. self.scrollView.contentSize = CGSizeMake(kScreenWidth*self.imageCount, 0);
  386. for(int i=0;i<self.imageCount;i++){
  387. UIView *cview = [UIView new];
  388. cview.tag = 1000+i;
  389. UITapGestureRecognizer *toplayAct = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toplayAct:)];
  390. [cview addGestureRecognizer:toplayAct];
  391. // cview.backgroundColor =[UIColor grayColor];
  392. [self.scrollView addSubview:cview];
  393. [cview mas_makeConstraints:^(MASConstraintMaker *make) {
  394. //375 340
  395. make.size.mas_equalTo(CGSizeMake(kScreenWidth, kScreenWidth*340/375));
  396. make.top.equalTo(self.scrollView);
  397. make.left.equalTo(self.scrollView).offset(kScreenWidth*i);
  398. }];
  399. UIImageView *iview = [UIImageView new];
  400. iview.contentMode = UIViewContentModeScaleToFill;
  401. // iview.backgroundColor = [UIColor blueColor]; horizontal_cover_url vertical_cover_url
  402. [iview sd_setImageWithURL:[NSURL URLWithString:self.banner[i][@"horizontal_cover_url"]]];
  403. [cview addSubview:iview];
  404. [iview mas_makeConstraints:^(MASConstraintMaker *make) {
  405. //375 340
  406. make.size.mas_equalTo(CGSizeMake(kScreenWidth, kScreenWidth*340/375));
  407. make.center.equalTo(cview);
  408. }];
  409. UILabel *nameLabel = [UILabel new];
  410. nameLabel.font= [UIFont systemFontOfSize:36];
  411. nameLabel.textColor = [UIColor whiteColor];
  412. // nameLabel.text = self.banner[i][@"ch_name"];
  413. [cview addSubview:nameLabel];
  414. [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  415. make.left.equalTo(cview).offset(16);
  416. make.top.equalTo(cview).offset(207);
  417. }];
  418. UIImageView *bimageview = [UIImageView new];
  419. bimageview.image = [UIImage imageNamed:@"Rectangle 57"];
  420. [cview addSubview:bimageview];
  421. [bimageview mas_makeConstraints:^(MASConstraintMaker *make) {
  422. make.top.equalTo(cview).offset(256);
  423. make.right.left.bottom.equalTo(cview);
  424. }];
  425. UILabel *contentLabel = [UILabel new];
  426. contentLabel.font= [UIFont systemFontOfSize:14];
  427. contentLabel.textColor = rgba(255, 255, 255, 0.6);
  428. // contentLabel.text = self.banner[i][@"simple_detail"];
  429. [cview addSubview:contentLabel];
  430. [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  431. make.left.equalTo(cview).offset(16);
  432. make.top.equalTo(cview).offset(256);
  433. }];
  434. CTPageControl *pc = [CTPageControl new];
  435. pc.numberOfPages = self.imageCount;
  436. pc.currentPage = i;
  437. pc.pageIndicatorTintColor = rgba(255, 255, 255, 0.6);
  438. pc.currentPageIndicatorTintColor = rgba(255, 186, 0, 1);
  439. [cview addSubview:pc];
  440. [pc mas_makeConstraints:^(MASConstraintMaker *make) {
  441. make.left.equalTo(cview).offset(-15);
  442. make.bottom.equalTo(cview).offset(-24);
  443. }];
  444. UIImageView *playView= [UIImageView new];
  445. playView.image = [UIImage imageNamed:@"Group 3"];
  446. [cview addSubview:playView];
  447. [playView mas_makeConstraints:^(MASConstraintMaker *make) {
  448. make.size.mas_equalTo(CGSizeMake(48, 48));
  449. make.right.equalTo(cview).offset(-16);
  450. make.top.equalTo(cview).offset(244);
  451. }];
  452. }
  453. }
  454. -(UIScrollView *)scrollView{
  455. if(!_scrollView){
  456. _scrollView = [[UIScrollView alloc] init];
  457. _scrollView.pagingEnabled = true;
  458. _scrollView.showsVerticalScrollIndicator = false;
  459. _scrollView.showsHorizontalScrollIndicator = false;
  460. }
  461. return _scrollView;
  462. }
  463. @end
  464. #pragma mark -- homecell2
  465. @interface homecell2()
  466. @property(nonatomic,strong)UIScrollView *scrollView;
  467. @end
  468. @implementation homecell2
  469. + (instancetype)cellWithTableView:(UITableView *)tableView{
  470. static NSString *identifier = @"homecell2";
  471. homecell2 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  472. if (cell == nil) {
  473. cell = [[homecell2 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  474. }
  475. return cell;
  476. }
  477. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  478. {
  479. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  480. if (self) {
  481. // [self creatView];
  482. }
  483. return self;
  484. }
  485. - (void)setHotmovies:(NSArray *)hotmovies{
  486. _hotmovies = hotmovies;
  487. [self.scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  488. [self.scrollView removeFromSuperview];
  489. [self creatView];
  490. }
  491. -(void)tapAct:(UITapGestureRecognizer *)g{
  492. NSInteger x = g.view.tag - 1000;
  493. int vid = [self.hotmovies[x][@"vid"] intValue];
  494. if(self.tapBlock){
  495. self.tapBlock(vid);
  496. }
  497. }
  498. -(void)addcollectAct:(UITapGestureRecognizer *)g{
  499. UIImageView *lefttop = (UIImageView *)g.view;
  500. NSInteger x = g.view.tag - 150;
  501. int vid = [self.hotmovies[x][@"vid"] intValue];
  502. if([UserModel collectContainVid:vid]){
  503. // [UserModel delCollect:self.hotmovies[x]];
  504. // lefttop.image = [UIImage imageNamed:@"Frame"];
  505. }else{
  506. [UserModel addCollect:self.hotmovies[x]];
  507. // lefttop.image = [UIImage imageNamed:@"Frame13"];
  508. lefttop.hidden = true;
  509. if(self.addCollectBlock){
  510. self.addCollectBlock();
  511. }
  512. }
  513. }
  514. -(void)creatView{
  515. self.selectionStyle = UITableViewCellSelectionStyleNone;
  516. self.backgroundColor = [UIColor clearColor];
  517. [self.contentView addSubview:self.scrollView];
  518. [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  519. make.size.mas_equalTo(CGSizeMake(kScreenWidth, 268));
  520. make.top.left.equalTo(self.contentView);
  521. }];
  522. if(self.hotmovies.count<2){
  523. self.scrollView.contentSize = CGSizeMake(0, 0);
  524. }else if(self.hotmovies.count<4){
  525. self.scrollView.contentSize = CGSizeMake(634-8 - 208 , 0);
  526. }else{
  527. self.scrollView.contentSize = CGSizeMake(634-8, 0);
  528. }
  529. // UIImageView * hv= [UIImageView new];
  530. // [self.contentView addSubview:hv];
  531. // [hv mas_makeConstraints:^(MASConstraintMaker *make) {
  532. // make.size.mas_equalTo(CGSizeMake(185, 268));
  533. // make.top.equalTo(self.contentView);
  534. // make.left.equalTo(self.scrollView).offset(12);
  535. // }];
  536. for(int i=0;i<self.hotmovies.count;i++){
  537. UIImageView * hvx= [UIImageView new];
  538. // hvx.backgroundColor = [UIColor redColor];
  539. if(i==0){
  540. [hvx sd_setImageWithURL:[NSURL URLWithString:self.hotmovies[i][@"vertical_cover_url"]]];
  541. }else{
  542. [hvx sd_setImageWithURL:[NSURL URLWithString:self.hotmovies[i][@"horizontal_cover_url"]]];
  543. }
  544. [self.scrollView addSubview:hvx];
  545. hvx.tag = 1000+i;
  546. hvx.userInteractionEnabled = true;
  547. UITapGestureRecognizer *g = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAct:)];
  548. [hvx addGestureRecognizer:g];
  549. if(i==0){
  550. [hvx mas_makeConstraints:^(MASConstraintMaker *make) {
  551. make.size.mas_equalTo(CGSizeMake(185, 268));
  552. make.top.equalTo(self.scrollView);
  553. make.left.equalTo(self.scrollView).offset(12);
  554. }];
  555. }else{
  556. [hvx mas_makeConstraints:^(MASConstraintMaker *make) {
  557. make.size.mas_equalTo(CGSizeMake(200, 130));
  558. if(i==3 || i==4){
  559. make.left.equalTo(self.scrollView).offset(205+8+200);
  560. }else{
  561. make.left.equalTo(self.scrollView).offset(205);
  562. }
  563. if(i==1 || i==3){
  564. make.top.equalTo(self.scrollView);
  565. }else{
  566. make.top.equalTo(self.scrollView).offset(138);
  567. }
  568. }];
  569. }
  570. UIImageView *lefttop = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
  571. if([UserModel collectContainVid:[self.hotmovies[i][@"vid"] intValue]]){
  572. // lefttop.image = [UIImage imageNamed:@"Frame13"];
  573. lefttop.hidden = true;
  574. }else{
  575. lefttop.image = [UIImage imageNamed:@"Frame"];
  576. lefttop.hidden = false;
  577. }
  578. lefttop.backgroundColor = rgba(19, 24, 42, 0.2);
  579. // 创建圆角路径
  580. UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:lefttop.bounds byRoundingCorners:UIRectCornerBottomRight cornerRadii:CGSizeMake(8, 8)];
  581. // 创建圆角图层
  582. CAShapeLayer *maskLayer = [CAShapeLayer layer];
  583. maskLayer.path = path.CGPath;
  584. lefttop.layer.mask = maskLayer;
  585. [hvx addSubview:lefttop];
  586. lefttop.tag = 150+i;
  587. lefttop.userInteractionEnabled = true;
  588. UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addcollectAct:)];
  589. [lefttop addGestureRecognizer:gest];
  590. [lefttop mas_makeConstraints:^(MASConstraintMaker *make) {
  591. make.size.mas_equalTo(CGSizeMake(24, 24));
  592. make.top.left.equalTo(hvx);
  593. }];
  594. UIImageView *righttop = [UIImageView new];
  595. righttop.image = [UIImage imageNamed:@"Rectangle 83"];
  596. [hvx addSubview:righttop];
  597. [righttop mas_makeConstraints:^(MASConstraintMaker *make) {
  598. make.size.mas_equalTo(CGSizeMake(40, 24));
  599. make.top.right.equalTo(hvx);
  600. }];
  601. UILabel *righttopText = [UILabel new];
  602. righttopText.font= [UIFont systemFontOfSize:14];
  603. righttopText.textColor = [UIColor whiteColor];
  604. righttopText.text = @"热门";
  605. [righttop addSubview:righttopText];
  606. [righttopText mas_makeConstraints:^(MASConstraintMaker *make) {
  607. make.center.equalTo(righttop);
  608. }];
  609. UIImageView *bottom = [UIImageView new];
  610. bottom.image = [UIImage imageNamed:@"Rectangle 57"];
  611. [hvx addSubview:bottom];
  612. [bottom mas_makeConstraints:^(MASConstraintMaker *make) {
  613. if(i==0){
  614. make.size.mas_equalTo(CGSizeMake(185, 64));
  615. }else{
  616. make.size.mas_equalTo(CGSizeMake(200, 50));
  617. }
  618. make.bottom.left.equalTo(hvx);
  619. }];
  620. UILabel *nameLabel = [UILabel new];
  621. nameLabel.font= [UIFont systemFontOfSize:14];
  622. nameLabel.textColor = [UIColor whiteColor];
  623. nameLabel.text = self.hotmovies[i][@"ch_name"];
  624. [bottom addSubview:nameLabel];
  625. [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  626. make.left.equalTo(bottom).offset(8);
  627. if(i==0){
  628. make.top.equalTo(bottom).offset(20);
  629. }else{
  630. make.top.equalTo(bottom).offset(4);
  631. }
  632. }];
  633. UILabel *contentLabel = [UILabel new];
  634. contentLabel.font= [UIFont systemFontOfSize:12];
  635. contentLabel.textColor = rgba(255, 255, 255, 0.4);
  636. contentLabel.text = self.hotmovies[i][@"simple_detail"] ;
  637. [bottom addSubview:contentLabel];
  638. [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  639. make.left.equalTo(bottom).offset(8);
  640. make.top.equalTo(nameLabel.mas_bottom);
  641. }];
  642. UILabel *scoreLabel = [UILabel new];
  643. scoreLabel.font= [UIFont boldSystemFontOfSize:16];
  644. scoreLabel.textColor = rgba(239, 164, 0, 1);
  645. scoreLabel.text = [NSString stringWithFormat:@"%.1f",[self.hotmovies[i][@"score"] floatValue]];
  646. [bottom addSubview:scoreLabel];
  647. [scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  648. make.right.equalTo(bottom).offset(-10);
  649. make.centerY.equalTo(contentLabel.mas_top);
  650. }];
  651. hvx.layer.cornerRadius = 8;
  652. hvx.layer.masksToBounds = YES;
  653. hvx.layer.shadowColor = [UIColor colorWithRed:0.05 green:0.086 blue:0.142 alpha:0.6].CGColor;
  654. hvx.layer.shadowOffset = CGSizeMake(0, 4);
  655. hvx.layer.shadowOpacity = 1;
  656. hvx.layer.shadowRadius = 20;
  657. }
  658. }
  659. -(UIScrollView *)scrollView{
  660. if(!_scrollView){
  661. _scrollView = [[UIScrollView alloc] init];
  662. _scrollView.pagingEnabled = true;
  663. _scrollView.showsVerticalScrollIndicator = false;
  664. _scrollView.showsHorizontalScrollIndicator = false;
  665. }
  666. return _scrollView;
  667. }
  668. @end
  669. #pragma mark -- homecell3
  670. @implementation homecell3
  671. + (instancetype)cellWithTableView:(UITableView *)tableView{
  672. static NSString *identifier = @"homecell3";
  673. homecell3 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  674. if (cell == nil) {
  675. cell = [[homecell3 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  676. }
  677. return cell;
  678. }
  679. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  680. {
  681. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  682. if (self) {
  683. [self creatView];
  684. }
  685. return self;
  686. }
  687. -(void)setTodayCommond:(NSArray *)todayCommond{
  688. _todayCommond = todayCommond;
  689. for(int i=0;i<3;i++){
  690. if(i<todayCommond.count){
  691. [self.contentView viewWithTag:1000+i].hidden = false;
  692. UIView *cview = [self.contentView viewWithTag:1000+i ];
  693. UIImageView *iv =[cview viewWithTag:100+i];
  694. [iv sd_setImageWithURL:[NSURL URLWithString:todayCommond[i][@"vertical_cover_url"]]];
  695. UILabel *lab =[cview viewWithTag:200+i];
  696. lab.text = [NSString stringWithFormat:@"%.1f",[todayCommond[i][@"score"] floatValue]];
  697. UILabel *lab2 =[cview viewWithTag:300+i];
  698. lab2.text = todayCommond[i][@"ch_name"];
  699. UILabel *lab3 =[cview viewWithTag:400+i];
  700. lab3.text = todayCommond[i][@"simple_detail"];
  701. UIImageView *lefttop=[iv viewWithTag:150+i];
  702. if([UserModel collectContainVid:[todayCommond[i][@"vid"] intValue]]){
  703. // lefttop.image = [UIImage imageNamed:@"Frame13"];
  704. lefttop.hidden = true;
  705. }else{
  706. lefttop.image = [UIImage imageNamed:@"Frame"];
  707. lefttop.hidden = false;
  708. }
  709. }else{
  710. [self.contentView viewWithTag:1000+i ].hidden = true;
  711. }
  712. }
  713. }
  714. -(void)Act:(UITapGestureRecognizer *)g{
  715. NSInteger x= g.view.tag - 1000;
  716. int vid = [self.todayCommond[x][@"vid"] intValue];
  717. if(self.tapBlock){
  718. self.tapBlock(vid);
  719. }
  720. }
  721. -(void)addcollectAct:(UITapGestureRecognizer *)g{
  722. NSInteger x= g.view.tag - 150;
  723. int vid = [self.todayCommond[x][@"vid"] intValue];
  724. UIImageView *lefttop = (UIImageView *)g.view;
  725. if([UserModel collectContainVid:vid]){
  726. // [UserModel delCollect:self.todayCommond[x]];
  727. // lefttop.image = [UIImage imageNamed:@"Frame"];
  728. }else{
  729. [UserModel addCollect:self.todayCommond[x]];
  730. // lefttop.image = [UIImage imageNamed:@"Frame13"];
  731. lefttop.hidden = true;
  732. if(self.addCollectBlock){
  733. self.addCollectBlock();
  734. }
  735. }
  736. }
  737. -(void)creatView{
  738. self.selectionStyle = UITableViewCellSelectionStyleNone;
  739. CGFloat m = (kScreenWidth - 3*112 - 24)/2;
  740. self.backgroundColor = [UIColor clearColor];
  741. for(int i=0;i<3;i++){
  742. UIView *cview =[UIView new];
  743. [self.contentView addSubview:cview];
  744. cview.tag = 1000+i;
  745. UITapGestureRecognizer *g=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Act:)];
  746. [cview addGestureRecognizer:g];
  747. [cview mas_makeConstraints:^(MASConstraintMaker *make) {
  748. make.size.mas_equalTo(CGSizeMake(112, 214));
  749. if(i==0){
  750. make.left.equalTo(self.contentView).offset(12);
  751. }else{
  752. make.left.equalTo(self.contentView).offset(12+(m+112)*i);
  753. }
  754. make.top.equalTo(self.contentView);
  755. }];
  756. UIImageView *imagev =[UIImageView new];
  757. imagev.tag = 100+i;
  758. imagev.image = [UIImage imageNamed:@"Rectangle 16"];
  759. [cview addSubview:imagev];
  760. [imagev mas_makeConstraints:^(MASConstraintMaker *make) {
  761. make.size.mas_equalTo(CGSizeMake(112, 146));
  762. make.left.equalTo(cview);
  763. make.top.equalTo(cview);
  764. }];
  765. UIImageView *lefttop = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
  766. lefttop.image = [UIImage imageNamed:@"Frame"];
  767. [imagev addSubview:lefttop];
  768. lefttop.tag = 150+i;
  769. lefttop.userInteractionEnabled = true;
  770. UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addcollectAct:)];
  771. [lefttop addGestureRecognizer:gest];
  772. [lefttop mas_makeConstraints:^(MASConstraintMaker *make) {
  773. make.size.mas_equalTo(CGSizeMake(24, 24));
  774. make.top.left.equalTo(imagev);
  775. }];
  776. lefttop.backgroundColor = rgba(19, 24, 42, 0.2);
  777. // 创建圆角路径
  778. UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:lefttop.bounds byRoundingCorners:UIRectCornerBottomRight cornerRadii:CGSizeMake(8, 8)];
  779. // 创建圆角图层
  780. CAShapeLayer *maskLayer = [CAShapeLayer layer];
  781. maskLayer.path = path.CGPath;
  782. lefttop.layer.mask = maskLayer;
  783. UIImageView *bimageview = [UIImageView new];
  784. bimageview.image = [UIImage imageNamed:@"Rectangle 57"];
  785. [imagev addSubview:bimageview];
  786. [bimageview mas_makeConstraints:^(MASConstraintMaker *make) {
  787. make.height.mas_equalTo(@35);
  788. make.bottom.left.right.equalTo(imagev);
  789. }];
  790. UILabel *scoreLabel = [UILabel new];
  791. scoreLabel.tag = 200+i;
  792. scoreLabel.font= [UIFont boldSystemFontOfSize:16];
  793. scoreLabel.textColor = rgba(239, 164, 0, 1);
  794. scoreLabel.text = @"9.4";
  795. [imagev addSubview:scoreLabel];
  796. [scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  797. make.right.equalTo(imagev).offset(-8);
  798. make.bottom.equalTo(imagev).offset(-6);
  799. }];
  800. UILabel *nameLabel = [UILabel new];
  801. nameLabel.tag = 300+i;
  802. nameLabel.font= [UIFont systemFontOfSize:14];
  803. nameLabel.textColor = [UIColor whiteColor];
  804. nameLabel.text = @"你的名字";
  805. [cview addSubview:nameLabel];
  806. [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  807. make.left.equalTo(cview);
  808. make.top.equalTo(imagev.mas_bottom).offset(8);
  809. }];
  810. UILabel *contentLabel = [UILabel new];
  811. contentLabel.tag = 400+i;
  812. contentLabel.font= [UIFont systemFontOfSize:12];
  813. contentLabel.textColor = rgba(255, 255, 255, 0.4);
  814. contentLabel.text = @"你的名字详情";
  815. [cview addSubview:contentLabel];
  816. [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  817. make.left.equalTo(cview);
  818. make.top.equalTo(nameLabel.mas_bottom);
  819. }];
  820. cview.layer.cornerRadius = 8;
  821. cview.layer.masksToBounds = YES;
  822. // imagev.layer.shadowColor = [UIColor colorWithRed:0.05 green:0.086 blue:0.142 alpha:0.6].CGColor;
  823. // imagev.layer.shadowOffset = CGSizeMake(0, 4);
  824. // imagev.layer.shadowOpacity = 1;
  825. // imagev.layer.shadowRadius = 20;
  826. }
  827. }
  828. @end
  829. #pragma mark -- headerView
  830. @interface headerView()
  831. @property(nonatomic,strong)UILabel *hl;
  832. @end
  833. @implementation headerView
  834. - (instancetype)init
  835. {
  836. self = [super init];
  837. if (self) {
  838. [self initView];
  839. }
  840. return self;
  841. }
  842. -(void)setTitle:(NSString *)title{
  843. _title = title;
  844. self.hl.text = title;
  845. }
  846. - (void)initView{
  847. self.hl = [UILabel new];
  848. self.hl.text = @"热门影视";
  849. self.hl.font = [UIFont boldSystemFontOfSize:16];
  850. self.hl.textColor =[UIColor whiteColor];
  851. self.hl.textAlignment = NSTextAlignmentLeft;
  852. [self addSubview:self.hl];
  853. [self.hl mas_makeConstraints:^(MASConstraintMaker *make) {
  854. make.left.equalTo(self).offset(12);
  855. make.top.right.bottom.equalTo(self);
  856. }];
  857. }
  858. @end
  859. #pragma mark -- home2cell1
  860. @interface home2cell1()
  861. @property(nonatomic,strong)UIScrollView *scrollView;
  862. @end
  863. @implementation home2cell1
  864. + (instancetype)cellWithTableView:(UITableView *)tableView{
  865. static NSString *identifier = @"home2cell1";
  866. home2cell1 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  867. if (cell == nil) {
  868. cell = [[home2cell1 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  869. }
  870. return cell;
  871. }
  872. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  873. {
  874. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  875. if (self) {
  876. // [self creatView];
  877. }
  878. return self;
  879. }
  880. -(void)setTopCommondData:(NSArray *)topCommondData{
  881. _topCommondData = topCommondData;
  882. self.imageCount = (int)topCommondData.count;
  883. }
  884. -(void)setImageCount:(int)imageCount{
  885. _imageCount = imageCount;
  886. [self.scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  887. [self.scrollView removeFromSuperview];
  888. [self creatView];
  889. }
  890. -(void)Act:(UITapGestureRecognizer *)g{
  891. NSInteger x= g.view.tag -1000;
  892. int vid = [self.topCommondData[x][@"vid"] intValue];
  893. if(self.tapBlock){
  894. self.tapBlock(vid);
  895. }
  896. }
  897. -(void)addcollectAct:(UITapGestureRecognizer *)g{
  898. NSInteger x= g.view.tag -150;
  899. int vid = [self.topCommondData[x][@"vid"] intValue];
  900. UIImageView *lefttop = (UIImageView *)g.view;
  901. if([UserModel collectContainVid:vid]){
  902. // [UserModel delCollect:self.topCommondData[x]];
  903. // lefttop.image = [UIImage imageNamed:@"Frame"];
  904. }else{
  905. [UserModel addCollect:self.topCommondData[x]];
  906. // lefttop.image = [UIImage imageNamed:@"Frame13"];
  907. lefttop.hidden = true;
  908. if(self.addCollectBlock){
  909. self.addCollectBlock();
  910. }
  911. }
  912. }
  913. -(void)creatView{
  914. self.selectionStyle = UITableViewCellSelectionStyleNone;
  915. self.backgroundColor = [UIColor clearColor];
  916. [self.contentView addSubview:self.scrollView];
  917. [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  918. make.size.mas_equalTo(CGSizeMake(kScreenWidth, 330));
  919. make.top.left.equalTo(self.contentView);
  920. }];
  921. self.scrollView.contentSize = CGSizeMake(24+(self.imageCount-1)*8 +self.imageCount*230 , 0);
  922. for(int i=0;i<self.imageCount;i++){
  923. UIView *cview = [UIView new];
  924. // cview.backgroundColor =[UIColor grayColor];
  925. [self.scrollView addSubview:cview];
  926. cview.tag = 1000+i;
  927. UITapGestureRecognizer *g=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Act:)];
  928. [cview addGestureRecognizer:g];
  929. [cview mas_makeConstraints:^(MASConstraintMaker *make) {
  930. make.size.mas_equalTo(CGSizeMake(230, 330));
  931. make.top.equalTo(self.scrollView);
  932. make.left.equalTo(self.scrollView).offset(12+(230+8)*i);
  933. }];
  934. UIImageView *iview = [UIImageView new];
  935. // iview.backgroundColor = [UIColor blueColor];
  936. [iview sd_setImageWithURL:[NSURL URLWithString:self.topCommondData[i][@"vertical_cover_url"]]];
  937. [cview addSubview:iview];
  938. [iview mas_makeConstraints:^(MASConstraintMaker *make) {
  939. make.size.mas_equalTo(CGSizeMake(230, 330));
  940. make.center.equalTo(cview);
  941. }];
  942. UIImageView *lefttop = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
  943. if([UserModel collectContainVid:[self.topCommondData[i][@"vid"] intValue]]){
  944. // lefttop.image = [UIImage imageNamed:@"Frame13"];
  945. lefttop.hidden = true;
  946. }else{
  947. lefttop.image = [UIImage imageNamed:@"Frame"];
  948. lefttop.hidden = false;
  949. }
  950. lefttop.backgroundColor = rgba(19, 24, 42, 0.2);
  951. // 创建圆角路径
  952. UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:lefttop.bounds byRoundingCorners:UIRectCornerBottomRight cornerRadii:CGSizeMake(8, 8)];
  953. // 创建圆角图层
  954. CAShapeLayer *maskLayer = [CAShapeLayer layer];
  955. maskLayer.path = path.CGPath;
  956. lefttop.layer.mask = maskLayer;
  957. // lefttop.image = [UIImage imageNamed:@"Frame"];
  958. [cview addSubview:lefttop];
  959. lefttop.tag = 150+i;
  960. lefttop.userInteractionEnabled = true;
  961. UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addcollectAct:)];
  962. [lefttop addGestureRecognizer:gest];
  963. [lefttop mas_makeConstraints:^(MASConstraintMaker *make) {
  964. make.size.mas_equalTo(CGSizeMake(16, 16));
  965. make.top.left.equalTo(cview);
  966. }];
  967. UIImageView *bimageview = [UIImageView new];
  968. bimageview.image = [UIImage imageNamed:@"Rectangle 57"];
  969. [cview addSubview:bimageview];
  970. [bimageview mas_makeConstraints:^(MASConstraintMaker *make) {
  971. make.size.mas_equalTo(CGSizeMake(230, 68));
  972. make.right.bottom.equalTo(cview);
  973. }];
  974. UILabel *nameLabel = [UILabel new];
  975. nameLabel.font= [UIFont systemFontOfSize:14];
  976. nameLabel.textColor = [UIColor whiteColor];
  977. nameLabel.text = self.topCommondData[i][@"ch_name"];
  978. [bimageview addSubview:nameLabel];
  979. [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  980. make.left.equalTo(bimageview).offset(8);
  981. make.top.equalTo(bimageview).offset(24);
  982. }];
  983. UILabel *contentLabel = [UILabel new];
  984. contentLabel.font= [UIFont systemFontOfSize:12];
  985. contentLabel.textColor = rgba(255, 255, 255, 0.4);
  986. contentLabel.text = self.topCommondData[i][@"simple_detail"];
  987. [bimageview addSubview:contentLabel];
  988. [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  989. make.left.equalTo(nameLabel);
  990. make.top.equalTo(nameLabel.mas_bottom);
  991. }];
  992. UILabel *scoreLabel = [UILabel new];
  993. scoreLabel.font= [UIFont boldSystemFontOfSize:16];
  994. scoreLabel.textColor = rgba(239, 164, 0, 1);
  995. scoreLabel.text = [NSString stringWithFormat:@"%.1f",[self.topCommondData[i][@"score"] floatValue]];
  996. [bimageview addSubview:scoreLabel];
  997. [scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  998. make.right.equalTo(bimageview).offset(-12);
  999. make.bottom.equalTo(bimageview).offset(-6);
  1000. }];
  1001. cview.layer.cornerRadius = 8;
  1002. cview.layer.masksToBounds = YES;
  1003. }
  1004. }
  1005. -(UIScrollView *)scrollView{
  1006. if(!_scrollView){
  1007. _scrollView = [[UIScrollView alloc] init];
  1008. // _scrollView.pagingEnabled = true;
  1009. _scrollView.showsVerticalScrollIndicator = false;
  1010. _scrollView.showsHorizontalScrollIndicator = false;
  1011. }
  1012. return _scrollView;
  1013. }
  1014. @end
  1015. #pragma mark -- home2cell2
  1016. @interface home2cell2()
  1017. @property(nonatomic,strong)UIView *cview;
  1018. @end
  1019. @implementation home2cell2
  1020. + (instancetype)cellWithTableView:(UITableView *)tableView{
  1021. static NSString *identifier = @"home2cell2";
  1022. home2cell2 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  1023. if (cell == nil) {
  1024. cell = [[home2cell2 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  1025. }
  1026. return cell;
  1027. }
  1028. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  1029. {
  1030. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  1031. if (self) {
  1032. [self creatView];
  1033. }
  1034. return self;
  1035. }
  1036. -(UIView *)cview{
  1037. if(!_cview){
  1038. _cview =[UIView new];
  1039. }
  1040. return _cview;
  1041. }
  1042. -(void)setObj:(NSDictionary *)obj{
  1043. _obj = obj;
  1044. UIImageView * hvx = [self.cview viewWithTag:100];
  1045. [hvx sd_setImageWithURL:[NSURL URLWithString:obj[@"horizontal_cover_url"]]];
  1046. UIImageView *icon = [[self.cview viewWithTag:200] viewWithTag:101];
  1047. [icon sd_setImageWithURL:[NSURL URLWithString:obj[@"vertical_cover_url"]]];
  1048. UILabel *lab1 = [[self.cview viewWithTag:200] viewWithTag:102];
  1049. lab1.text = obj[@"ch_name"];
  1050. UILabel *lab2 = [[self.cview viewWithTag:200] viewWithTag:103];
  1051. lab2.text = obj[@"simple_detail"];
  1052. UILabel *lab3 = [[self.cview viewWithTag:200] viewWithTag:104];
  1053. lab3.text = obj[@"simple_detail"];
  1054. UILabel *lab4 = [[self.cview viewWithTag:200] viewWithTag:105];
  1055. lab4.text = [NSString stringWithFormat:@"%.1f",[obj[@"score"] floatValue]];
  1056. UIImageView *lefttop = [self.cview viewWithTag:150];
  1057. if([UserModel collectContainVid:[obj[@"vid"] intValue]]){
  1058. // lefttop.image = [UIImage imageNamed:@"Frame13"];
  1059. lefttop.hidden = true;
  1060. }else{
  1061. lefttop.image = [UIImage imageNamed:@"Frame"];
  1062. lefttop.hidden = false;
  1063. }
  1064. }
  1065. -(void)Act:(UITapGestureRecognizer *)g{
  1066. int vid = [self.obj[@"vid"] intValue];
  1067. if(self.tapBlock){
  1068. self.tapBlock(vid);
  1069. }
  1070. }
  1071. -(void)addcollectAct:(UITapGestureRecognizer *)g{
  1072. int vid = [self.obj[@"vid"] intValue];
  1073. UIImageView *lefttop = (UIImageView *)g.view;
  1074. if([UserModel collectContainVid:vid]){
  1075. // [UserModel delCollect:self.obj];
  1076. // lefttop.image = [UIImage imageNamed:@"Frame"];
  1077. }else{
  1078. [UserModel addCollect:self.obj];
  1079. // lefttop.image = [UIImage imageNamed:@"Frame13"];
  1080. lefttop.hidden = true;
  1081. if(self.addCollectBlock){
  1082. self.addCollectBlock();
  1083. }
  1084. }
  1085. }
  1086. -(void)creatView{
  1087. self.selectionStyle = UITableViewCellSelectionStyleNone;
  1088. self.backgroundColor = [UIColor clearColor];
  1089. [self.contentView addSubview:self.cview];
  1090. [self.cview mas_makeConstraints:^(MASConstraintMaker *make) {
  1091. make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-24, 272));
  1092. make.top.equalTo(self.contentView);
  1093. make.left.equalTo(self.contentView).offset(12);
  1094. }];
  1095. UITapGestureRecognizer *g=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Act:)];
  1096. [self.cview addGestureRecognizer:g];
  1097. UIImageView * hvx= [UIImageView new];
  1098. // hvx.backgroundColor = [UIColor redColor];
  1099. hvx.tag=100;
  1100. [self.cview addSubview:hvx];
  1101. [hvx mas_makeConstraints:^(MASConstraintMaker *make) {
  1102. make.edges.equalTo(self.cview);
  1103. }];
  1104. UIImageView *lefttop = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
  1105. lefttop.image = [UIImage imageNamed:@"Frame"];
  1106. [self.cview addSubview:lefttop];
  1107. lefttop.tag = 150;
  1108. lefttop.userInteractionEnabled = true;
  1109. UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addcollectAct:)];
  1110. [lefttop addGestureRecognizer:gest];
  1111. [lefttop mas_makeConstraints:^(MASConstraintMaker *make) {
  1112. make.size.mas_equalTo(CGSizeMake(24, 24));
  1113. make.top.left.equalTo(self.cview );
  1114. }];
  1115. lefttop.backgroundColor = rgba(19, 24, 42, 0.2);
  1116. // 创建圆角路径
  1117. UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:lefttop.bounds byRoundingCorners:UIRectCornerBottomRight cornerRadii:CGSizeMake(8, 8)];
  1118. // 创建圆角图层
  1119. CAShapeLayer *maskLayer = [CAShapeLayer layer];
  1120. maskLayer.path = path.CGPath;
  1121. lefttop.layer.mask = maskLayer;
  1122. UIView *bottomV = [UIView new];
  1123. bottomV.tag = 200;
  1124. bottomV.backgroundColor = rgba(30, 46, 63, 1);
  1125. [self.cview addSubview:bottomV];
  1126. [bottomV mas_makeConstraints:^(MASConstraintMaker *make) {
  1127. make.height.mas_equalTo(@75);
  1128. make.bottom.left.right.equalTo(self.cview);
  1129. }];
  1130. UIImageView *icon = [UIImageView new];
  1131. // icon.image = [UIImage imageNamed:@"Rectangle 83"];
  1132. icon.tag = 101;
  1133. // icon.backgroundColor = [UIColor darkGrayColor];
  1134. [bottomV addSubview:icon];
  1135. [icon mas_makeConstraints:^(MASConstraintMaker *make) {
  1136. make.size.mas_equalTo(CGSizeMake(45, 59));
  1137. make.top.equalTo(bottomV).offset(8);
  1138. make.left.equalTo(bottomV).offset(8);
  1139. }];
  1140. UILabel *nameLabel = [UILabel new];
  1141. nameLabel.font= [UIFont systemFontOfSize:14];
  1142. nameLabel.textColor = [UIColor whiteColor];
  1143. nameLabel.tag = 102;
  1144. nameLabel.text = @"你的名字";
  1145. [bottomV addSubview:nameLabel];
  1146. [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  1147. make.left.equalTo(icon.mas_right).offset(8);
  1148. make.top.equalTo(icon);
  1149. }];
  1150. UILabel *contentLabel = [UILabel new];
  1151. contentLabel.font= [UIFont systemFontOfSize:12];
  1152. contentLabel.textColor = rgba(255, 255, 255, 0.4);
  1153. contentLabel.tag = 103;
  1154. contentLabel.text = @"你的名字详情";
  1155. [bottomV addSubview:contentLabel];
  1156. [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  1157. make.left.equalTo(nameLabel);
  1158. // make.top.equalTo(nameLabel.mas_bottom);
  1159. make.centerY.equalTo(icon);
  1160. }];
  1161. UILabel *styleLabel = [UILabel new];
  1162. styleLabel.font= [UIFont systemFontOfSize:12];
  1163. styleLabel.textColor = rgba(255, 255, 255, 0.4);
  1164. styleLabel.text = @"奥斯卡获奖佳片";
  1165. styleLabel.tag = 104;
  1166. [bottomV addSubview:styleLabel];
  1167. [styleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  1168. make.left.equalTo(nameLabel);
  1169. make.bottom.equalTo(icon);
  1170. }];
  1171. UILabel *scoreLabel = [UILabel new];
  1172. scoreLabel.font= [UIFont boldSystemFontOfSize:18];
  1173. scoreLabel.textColor = rgba(239, 164, 0, 1);
  1174. scoreLabel.text = @"9.4";
  1175. scoreLabel.tag = 105;
  1176. [bottomV addSubview:scoreLabel];
  1177. [scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  1178. make.right.equalTo(bottomV).offset(-8);
  1179. make.bottom.equalTo(bottomV).offset(-8);
  1180. }];
  1181. icon.layer.cornerRadius = 6;
  1182. icon.layer.masksToBounds = YES;
  1183. self.cview.layer.cornerRadius = 8;
  1184. self.cview.layer.masksToBounds = YES;
  1185. // hvx.layer.shadowColor = [UIColor colorWithRed:0.05 green:0.086 blue:0.142 alpha:0.6].CGColor;
  1186. // hvx.layer.shadowOffset = CGSizeMake(0, 4);
  1187. // hvx.layer.shadowOpacity = 1;
  1188. // hvx.layer.shadowRadius = 20;
  1189. }
  1190. @end