#import "HmV3.h" #import "STButton.h" #import "AdvertisingColumn.h" #import "TRListVC.h" #import "TRDetailVC.h" #import "TopicesVC.h" #import "VowBar.h" #import "CLCell.h" #import "LightingAndSoundVC.h" @interface HmV3 () { NSArray *arr; NSArray *videoArray; NSMutableArray *array; NSMutableArray *dataArray; UITableView *_tableView; VowBar *vowItem; UIView *videoView; AdvertisingColumn *adView; } @end @implementation HmV3 - (void)viewDidLoad { [super viewDidLoad]; [self myInit]; [self getVideos]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)myInit { self.view.height = self.viewH; [self.view setBackgroundColor:backGroundColor]; [self configNavigationBar]; arr = @[@"科目三考试评判标准,提前了解不失分", @"科目三原来是这样丢分的", @"三招提高科目三考试成功率", @"科目三考试详细流程", @"科三再升级“人考”改“机考”车内多名安全员", @"科目三--加减档位操作", @"夜考,用这几招轻轻松松过", @"科目三大路考之靠边停车小技巧", @"科目三:模拟夜间行驶场景灯光使用技巧", @"超详细科目三考试口令速记口诀!", @"控制科目三方向的几个生死关键点", @"2015年科目三考试新规则和扣分标准", @"科目三:路考超车须知", @"科目三:电子路考需要注意什么", @"科目三:老手教你靠边停车技术", @"科目三:路考变更车道须知", @"科目三:路考通过人行横道线须知", @"科目三:路考中14项细节必需注意", @"考试指南 - 科目三路考评判标准", @"考试指南 - 科目三路考秘诀", @"考试指南 - 科目三必过的考场经验分享", @"考试指南 - 科目三抽到夜间考试怎么办?", @"考试指南 - 夜考灯光使用攻略,看完就过了!", @"考试指南 - 科目三路考会车攻略"]; array = [NSMutableArray arrayWithArray:arr]; dataArray = [NSMutableArray array]; for (int i = 0; i < 5; i ++) { int index = arc4random()%(array.count - 1); [dataArray addObject:array[index]]; [array removeObjectAtIndex:index]; } scroll = self.zzScrollV; [scroll setScrollEnabled:YES]; [self.view addSubview:scroll]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateAD:) name:@"updateAD" object:nil]; adView = [[AdvertisingColumn alloc]initWithFrame:CGRectMake(0, 0, kSize.width, kSize.width*9/32.0)]; //广告 NSMutableArray *newAD = [NSMutableArray array]; for (NSDictionary *dic in myDelegate.adArray) { if ([dic[@"LOCATION"] isEqualToString:@"5"]) { [newAD addObject:dic]; } } [adView setImgArray:newAD]; adView.supVC = self; [scroll addSubview:adView]; CGFloat btnW = kSize.width/4; CGFloat btnH = 90; UIView* btnBg = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(adView.frame), kSize.width, btnH)]; [btnBg setBackgroundColor:[UIColor whiteColor]]; [scroll addSubview:btnBg]; NSInteger tag =0; NSArray* titles = @[@"评判标准",@"路考秘诀",@"考场经验",@"秘籍指导"]; NSArray* images = @[@"subject3_secret_guide_icon.png",@"subject2_standart_icon.png", @"subject1_apply_know_icon.png",@"subject1_newbie_onroad_icon.png"]; for (int i =0; i>"; [vowItem.topicBtn addTarget:self action:@selector(vowClick:) forControlEvents:UIControlEventTouchUpInside]; vowItem.topicBtn.tag = 11; [vowItem.vomBtn addTarget:self action:@selector(vowClick:) forControlEvents:UIControlEventTouchUpInside]; vowItem.vomBtn.tag = 12; // [scroll addSubview:vowItem]; [scroll setContentSize:CGSizeMake(0, CGRectGetMaxY(vowItem.frame)+SCRV_BottomH)]; } - (void)updateAD:(NSNotification *)notifica { NSMutableArray *newAD = [NSMutableArray array]; for (NSDictionary *dic in myDelegate.adArray) { if ([dic[@"LOCATION"] isEqualToString:@"5"]) { [newAD addObject:dic]; } } [adView setImgArray:newAD]; [[NSNotificationCenter defaultCenter] removeObserver:self name:@"updateAD" object:nil]; } -(void)vowClick:(UIButton *)btn { TopicesVC* vc = [[TopicesVC alloc] init]; vc.type = @"1"; if (btn.tag == 11) { vc.groupId = @"6"; } else { vc.groupId = @"9"; } [self navPushHideTabbarToVC:vc]; } #pragma mark tableView delegate - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return dataArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { CLCell *cell= [CLCell cellForTableView:tableView Style:UITableViewCellStyleDefault]; [cell.textLabel setText:dataArray[indexPath.row]]; [cell.imageView setImage:defaultImg]; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; TRDetailVC *vc=[[TRDetailVC alloc]init]; [vc setFile:dataArray[indexPath.row]]; [self navPushHideTabbarToVC:vc]; } -(void)btnClick:(STButton*)sender { if (0 == sender.tag) { TRDetailVC* vc = [[TRDetailVC alloc] init]; [vc setFile:@"科目三评判标准"]; [self navPushHideTabbarToVC:vc]; return; } if (1 == sender.tag) { TRDetailVC* vc = [[TRDetailVC alloc] init]; [vc setFile:@"科目三路考秘诀"]; [self navPushHideTabbarToVC:vc]; return; } if (2 == sender.tag) { TRDetailVC* vc = [[TRDetailVC alloc] init]; [vc setFile:@"科目三考场经验"]; [self navPushHideTabbarToVC:vc]; return; } if (3 == sender.tag) { TRListVC* vc = [[TRListVC alloc] init]; arr = @[@"科目三考试评判标准,提前了解不失分", @"科目三原来是这样丢分的", @"三招提高科目三考试成功率", @"科目三考试详细流程", @"科三再升级“人考”改“机考”车内多名安全员", @"科目三--加减档位操作", @"夜考,用这几招轻轻松松过", @"科目三大路考之靠边停车小技巧", @"科目三:模拟夜间行驶场景灯光使用技巧", @"超详细科目三考试口令速记口诀!", @"控制科目三方向的几个生死关键点", @"2015年科目三考试新规则和扣分标准", @"科目三:路考超车须知", @"科目三:电子路考需要注意什么", @"科目三:老手教你靠边停车技术", @"科目三:路考变更车道须知", @"科目三:路考通过人行横道线须知", @"科目三:路考中14项细节必需注意", @"考试指南 - 科目三路考评判标准", @"考试指南 - 科目三路考秘诀", @"考试指南 - 科目三必过的考场经验分享", @"考试指南 - 科目三抽到夜间考试怎么办?", @"考试指南 - 夜考灯光使用攻略,看完就过了!", @"考试指南 - 科目三路考会车攻略"]; [vc setModels:arr]; [vc setTitle:@"秘籍指导"]; [self navPushHideTabbarToVC:vc]; return; } if (sender.tag == 4 || sender.tag == 5) { LightingAndSoundVC *VC = [[LightingAndSoundVC alloc] init]; VC.styleTag = sender.tag; [self navPushHideTabbarToVC:VC]; } if (6 == sender.tag) { // DownLoadVC *downLoadVC = [[DownLoadVC alloc] init]; // downLoadVC.subject = 3; // // [self navPushHideTabbarToVC:downLoadVC]; // VideoDownLoadListVC *downLoadVC = [[VideoDownLoadListVC alloc] init]; // downLoadVC.videoListSegControlIndex = VideoListSegControlIndex_ObjectThree; // [self navPushHideTabbarToVC:downLoadVC]; } if (sender.tag > 6 && sender.tag < 13) { // VideoPlayVC *vc = [[VideoPlayVC alloc] init]; // if (videoArray.count > 5) { // vc.dataDic = videoArray[sender.tag - 7]; // } // vc.subject = 3; // [self navPushHideTabbarToVC:vc]; // LeeVideoVC *vc = [[LeeVideoVC alloc]init]; // if (videoArray.count > 5) { // vc.dataDic = videoArray[sender.tag - 7]; // } // vc.subject = 3; // vc.goDownLoadBlock = ^{ // DownLoadVC *downLoadVC = [[DownLoadVC alloc] init]; // downLoadVC.subject = 3; // [self navPushHideTabbarToVC:downLoadVC]; // }; // vc.modalPresentationStyle = UIModalPresentationFullScreen; // [self presentViewController:vc animated:YES completion:nil]; // VideoPlayViewController *vc = [[VideoPlayViewController alloc] init]; // if (videoArray.count > 5) { // NSDictionary *dic = videoArray[sender.tag - 7]; // RQDownloadModel *downloadModel = [[RQDownloadModel alloc] init]; // downloadModel.videoId = dic[@"id"]; // downloadModel.subject = dic[@"subject"]; // downloadModel.title = dic[@"title"]; // downloadModel.urlString = dic[@"videoPath"]; // downloadModel.imageUrl = dic[@"image"]; // downloadModel.content = dic[@"content"]; // vc.currentModel = downloadModel; // } // [self navPushHideTabbarToVC:vc]; } } #pragma mark 获取视频资源 -(void)getVideos { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray *aArray=[NSMutableArray array]; [aArray addPro:@"chapterId" Value:@"3"]; [aArray addPro:@"subject" Value:@"3"]; [aArray addPro:@"isPage" Value:@"0"]; [aArray addPro:@"pageSize" Value:@"0"]; [aArray addPro:@"currentPage" Value:@"0"]; NSString* method = @"getVideos"; [jiaPeiManager requestAnythingWithURL:method array:aArray data:nil completion:^(NSDictionary *root) { //NSLog(@"获取视频aArray-->%@------------------root-->%@",aArray,root); if (!root) { // ShowMsg(@"操作失败!请重试"); return ; } if ([root[@"code"] isEqualToString:@"1"]) { return; } if ([root[@"body"] count] > 5) { videoArray = root[@"body"]; [self initVideoView]; //NSLog(@"-%d---%@",(int)videoArray.count,videoArray); }else{ //其实这个是多余的 因为这个页面每次进来只会加载一次 就是说这个方法只会调用一次 if ([videoView isKindOfClass:[UIView class]]) { [_tableView setHidden:NO]; [videoView removeFromSuperview]; vowItem.y = [[scroll subviews] lastObject].bottom + 10; [scroll setContentSize:CGSizeMake(0, CGRectGetMaxY(vowItem.frame)+SCRV_BottomH)]; } } }]; } -(void)initVideoView { [_tableView setHidden:YES]; //290*260 290*180 290*70 videoView = [[UIView alloc] initWithFrame:_tableView.frame]; videoView.backgroundColor = [UIColor whiteColor]; //重置页面展示形式 CGFloat w = (kSize.width - 30)/2.0; videoView.height = w*78/29.0 + 40; [scroll addSubview:videoView]; vowItem.y = videoView.bottom + 10; [scroll setContentSize:CGSizeMake(0, CGRectGetMaxY(vowItem.frame)+SCRV_BottomH)]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, kSize.width/2.0 - 10, 40)]; [label setText:@"教学视频" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft]; [videoView addSubview:label]; label = [[UILabel alloc] initWithFrame:CGRectMake(kSize.width/2.0, 0, kSize.width/2.0 - 10, 40)]; [label setText:[NSString stringWithFormat:@"共%d个视频>",(int)videoArray.count] Font:Font17 TextColor:contentTextColor Alignment:NSTextAlignmentRight]; [videoView addSubview:label]; UIButton *moreVideoBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 40)]; [moreVideoBtn target:self tag:6];//tag 6开始 [videoView addSubview:moreVideoBtn]; CGFloat bdH = w*26/29.0; CGFloat photoH = w*18/29.0; CGFloat labelH = w*7/29.0; NSInteger videoNum = videoArray.count; if (videoNum > 6) { videoNum = 6; } for (int i = 0; i < videoNum; i ++) { int row = i/2; int clumn = i%2; NSDictionary *dic = videoArray[i]; //照片 UIImageView *videoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10 + clumn*(w + 10), 40 + row*bdH, w, photoH)]; NSString *str = dic[@"image"]; if (str && ![str hasPrefix:@"http"]){ str = [imgPreFix stringByAppendingString:str]; } if (!str) { str = @""; } [videoImageView sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"NOIMG.png"]]; [videoView addSubview:videoImageView]; //时长 label = [[UILabel alloc] initWithFrame:CGRectMake(10 + clumn*(w + 10), row*bdH + photoH + 15, w - 10, 25)]; label.backgroundColor = windowBlockColor; int seconds = [dic[@"times"] intValue]; NSString *min = [NSString stringWithFormat:@"%d",seconds/60]; NSString *sec = [NSString stringWithFormat:@"%d",seconds%60]; if (seconds/60 < 10) { min = [NSString stringWithFormat:@"0%@",min]; } if (seconds%60 < 10) { sec = [NSString stringWithFormat:@"0%@",sec]; } [label setText:[NSString stringWithFormat:@"%@:%@",min,sec] Font:NormalFont TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentRight]; [videoView addSubview:label]; //title label = [[UILabel alloc] initWithFrame:CGRectMake(10 + clumn*(w + 10), 40 + row*bdH + photoH, w, labelH)]; [label setText:dic[@"title"] Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft]; [videoView addSubview:label]; //btn UIButton *playBtn = [[UIButton alloc] initWithFrame:CGRectMake(10 + clumn*(w + 10), 40 + row*bdH, w, bdH)]; playBtn.backgroundColor = [UIColor clearColor]; [playBtn target:self tag:7 + i];//7开始 [videoView addSubview:playBtn]; } } -(void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self name:@"updateAD" object:nil]; //下边这个其实不用写的 我们的项目应该不会被用在arc环境下 #if ! __has_feature(objc_arc) [super dealloc]; #endif } @end