| | |
| | | #import "LookNoteController.h" |
| | | #import "XYRDetailViewController.h" |
| | | #import "XYRVideoInfoModel.h" |
| | | #import "SDCycleScrollView.h" |
| | | #import "recommentCollectionViewCell.h" |
| | | #import "shufflingCollectionReusableView.h" |
| | | #import "HeaderCollectionReusableView.h" |
| | |
| | | |
| | | @import GoogleMobileAds;//谷歌广告 |
| | | |
| | | @interface SubregionDetailViewController ()<UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource,SDCycleScrollViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,GADNativeAppInstallAdLoaderDelegate, GADNativeContentAdLoaderDelegate>{ |
| | | @interface SubregionDetailViewController ()<UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,GADNativeAppInstallAdLoaderDelegate, GADNativeContentAdLoaderDelegate>{ |
| | | NSInteger SpeciesNumber;//种类的位置 |
| | | NSInteger typeNumber;//细分类 |
| | | |
| | | UICollectionView *recommendation;//推荐页面的collectionView |
| | | SDCycleScrollView *_cycleScrollView;//头部的推荐轮播图 |
| | | |
| | | BOOL googleNoAdToShow;//当这个变量为YES时,说明谷歌广告没有资源 |
| | | BOOL LoadGoogleAD;//是否选择加载谷歌广告 |
| | |
| | | |
| | | @property(nonatomic, strong) GADAdLoader *adLoader;//谷歌广告 |
| | | @property(nonatomic, strong) UIView *nativeAdView;//装载谷歌广告的视图 |
| | | @property (weak, nonatomic) IBOutlet NSLayoutConstraint *toplayout; |
| | | @property (nonatomic,assign)NSInteger kNavHeight; |
| | | |
| | | @property (weak, nonatomic) IBOutlet UIButton *topButton; |
| | | |
| | | |
| | | @end |
| | | |
| | |
| | | |
| | | - (void)viewDidLoad { |
| | | [super viewDidLoad]; |
| | | if (KIsiPhoneX) { |
| | | self.kNavHeight = 84; |
| | | }else{ |
| | | self.kNavHeight = 64; |
| | | } |
| | | //加载定制的导航栏视图 |
| | | [self loadNavigationView]; |
| | | //请求种类数据 |
| | | [self getDataFirstChildType]; |
| | | //添加分段显示器的属性 |
| | | |
| | | [self addSegment]; |
| | | if (KIsiPhoneX) { |
| | | _toplayout .constant = 130; |
| | | }else{ |
| | | _toplayout.constant = 110; |
| | | } |
| | | } |
| | | |
| | | - (void)viewWillAppear:(BOOL)animated |
| | |
| | | self.navigationItem.rightBarButtonItems=[[NSArray alloc] initWithObjects:SearchBarItem,WhiteBarItem,recordBarItem,nil]; |
| | | } |
| | | |
| | | - (IBAction)topTaped:(UIButton *)sender { |
| | | UITableView *tableview = [self.view viewWithTag:800 + SpeciesNumber ]; |
| | | NSIndexPath* indexPat = [NSIndexPath indexPathForRow:0 inSection:0]; |
| | | [tableview scrollToRowAtIndexPath:indexPat atScrollPosition:UITableViewScrollPositionBottom animated:YES]; |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 滑动视图 |
| | | */ |
| | | -(void)addScrollerView{ |
| | | //配置滑动视图 |
| | | self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, kNavigationBarH+40, KScreenW, KScreenH-kNavigationBarH-40)]; |
| | | NSInteger index = KIsiPhoneX ? 84 :64 ; |
| | | |
| | | self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, self.kNavHeight+40, KScreenW, KScreenH-self.kNavHeight-40)]; |
| | | self.scrollView.pagingEnabled = YES; |
| | | self.scrollView.showsHorizontalScrollIndicator = NO; |
| | | self.scrollView.showsVerticalScrollIndicator=NO; |
| | | self.scrollView.bounces=NO; |
| | | self.scrollView.contentSize = CGSizeMake(KScreenW * _SpeciesAry.count, KScreenH-kNavigationBarH-40); |
| | | self.scrollView.contentSize = CGSizeMake(KScreenW * _SpeciesAry.count, KScreenH-self.kNavHeight-40); |
| | | self.scrollView.delegate = self; |
| | | [self.scrollView scrollRectToVisible:CGRectMake(0, 0, KScreenW, KScreenH-kNavigationBarH-40) animated:NO]; |
| | | [self.scrollView scrollRectToVisible:CGRectMake(0, 0, KScreenW, KScreenH-self.kNavHeight-40) animated:NO]; |
| | | [self.view addSubview:self.scrollView]; |
| | | |
| | | // //推荐页面的视图 |
| | | // if (!recommendation) { |
| | | // UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init]; |
| | | // //指定布局方式为垂直 |
| | | // flow.scrollDirection = UICollectionViewScrollDirectionVertical; |
| | | // flow.minimumLineSpacing = 10;//最小行间距(当垂直布局时是行间距,当水平布局时可以理解为列间距) |
| | | // flow.minimumInteritemSpacing = 10;//两个单元格之间的最小间距 |
| | | // recommendation=[[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, KScreenH-kNavigationBarH-40) collectionViewLayout:flow]; |
| | | // } |
| | | // recommendation.delegate=self; |
| | | // recommendation.dataSource=self; |
| | | // recommendation.backgroundColor=kGlobalBackgroundColor; |
| | | // //注册cell |
| | | // [recommendation registerNib:[UINib nibWithNibName:@"recommentCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"recommentCollectionViewCell"]; |
| | | // //设置轮播图的head |
| | | // [recommendation registerNib:[UINib nibWithNibName:@"shufflingCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"shufflingCollectionReusableView"]; |
| | | // //设置分类头的head |
| | | // [recommendation registerNib:[UINib nibWithNibName:@"HeaderCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderCollectionReusableView"]; |
| | | // |
| | | // //推荐视图 |
| | | // [self.scrollView addSubview:recommendation]; |
| | | // //给collectionView设置下拉刷新 |
| | | // recommendation.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{ |
| | | // //开始刷新 |
| | | // [recommendation.mj_header beginRefreshing]; |
| | | // //网络请求 |
| | | // [self getVideoBanner]; |
| | | // [self VideoList]; |
| | | // }]; |
| | | // |
| | | |
| | | //非推荐界面视图 |
| | | for (int i=0; i<_SpeciesAry.count; i++) { |
| | | UITableView *scollerTableView=[[UITableView alloc] initWithFrame:CGRectMake(KScreenW*i, 40, KScreenW, KScreenH-kNavigationBarH-80) style:UITableViewStylePlain]; |
| | | UITableView *scollerTableView=[[UITableView alloc] initWithFrame:CGRectMake(KScreenW*i, 40 , KScreenW, KScreenH-self.kNavHeight-80) style:UITableViewStylePlain]; |
| | | scollerTableView.tag=800+i; |
| | | scollerTableView.delegate=self; |
| | | scollerTableView.dataSource=self; |
| | |
| | | [_TitleForshuffling addObject:[[[_CycleScrollData objectAtIndex:i] objectForKey:@"VideoInfo"]objectForKey:@"Name"]]; |
| | | } |
| | | } |
| | | _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0,KScreenW, KScreenW*7/16) imageURLStringsGroup:_addrssForshuffling]; |
| | | _cycleScrollView.titlesGroup=_TitleForshuffling; |
| | | _cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight; |
| | | _cycleScrollView.currentPageDotColor=kGlobalYellowColor; |
| | | _cycleScrollView.delegate = self; |
| | | _cycleScrollView.placeholderImage = [UIImage imageNamed:@"默认加载图片"]; |
| | | } |
| | | |
| | | |
| | |
| | | _segmentedControl.backgroundColor=kGlobalMainColor; |
| | | _segmentedControl.selectionIndicatorHeight = 2.0f; |
| | | _segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth; |
| | | _segmentedControl.frame = CGRectMake(0, kNavigationBarH, KScreenW, 40); |
| | | _segmentedControl.frame = CGRectMake(0, self.kNavHeight, KScreenW, 40); |
| | | _segmentedControl.segmentEdgeInset = UIEdgeInsetsMake(0, 10, 0, 10); |
| | | _segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleFullWidthStripe; |
| | | _segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown; |
| | |
| | | typeNumber=1; |
| | | weakSelf.segView.selectedSegmentIndex=0; |
| | | weakSelf.Species = [NSString stringWithFormat:@"%@",[[weakSelf.SpeciesAry objectAtIndex:SpeciesNumber] objectForKey:@"Id"]]; |
| | | [weakSelf.scrollView scrollRectToVisible:CGRectMake(KScreenW * index, kNavigationBarH+40, KScreenW, KScreenH-kNavigationBarH-40) animated:YES]; |
| | | [weakSelf.scrollView scrollRectToVisible:CGRectMake(KScreenW * index, self.kNavHeight+40, KScreenW, KScreenH-self.kNavHeight-40) animated:YES]; |
| | | // if (index==0) { |
| | | // [self.view sendSubviewToBack:_segView]; |
| | | // if (_CycleScrollData==nil&&_hotListData==nil) { |
| | |
| | | |
| | | //添加滑动视图 |
| | | [self addScrollerView]; |
| | | [self.view bringSubviewToFront:self.topButton]; |
| | | } |
| | | |
| | | -(void)changeTheClassifyWith:(NSInteger)index{ |
| | |
| | | _SpeciesAry = [[NSMutableArray alloc] initWithCapacity:0]; |
| | | } |
| | | _SpeciesAry = [[dic objectForKey:@"Data"] objectForKey:@"data"]; |
| | | [_SpeciesAry removeObjectAtIndex:0]; |
| | | // [_SpeciesAry removeObjectAtIndex:0]; |
| | | NSLog(@"%@",_SpeciesAry); |
| | | _Species = [NSString stringWithFormat:@"%@",[[_SpeciesAry objectAtIndex:0] objectForKey:@"Id"]]; |
| | | _CategoryType=[NSString stringWithFormat:@"%@",[[_SpeciesAry objectAtIndex:0] objectForKey:@"CategoryType"]]; |
| | |
| | | [self getaddView]; |
| | | }else{ |
| | | //报错 |
| | | if ([error compare:@"似乎已断开与互联网的连接。"] == 0) { |
| | | [self autoDisappearAlertTime:1 msg:@"网络不可用,请检查网络"]; |
| | | } |
| | | NSLog(@"%@",error); |
| | | } |
| | | }]; |
| | | } |
| | |
| | | */ |
| | | - (void)getdataClassVideoWithPage:(NSInteger)page{ |
| | | [[YTHNetInterface startInterface] getVideoListWithUid:[YTHsharedManger startManger].Uid withPage:[NSString stringWithFormat:@"%ld",(long)page] withVideoType:_Species withOrder:[NSString stringWithFormat:@"%ld",(long)typeNumber] withSystem:@"1" withCategoryType:_CategoryType withBlock:^(BOOL isSuccessful, id result, NSString *error) { |
| | | NSLog(@"%@",result); |
| | | if (isSuccessful) { |
| | | NSDictionary *dic = (NSDictionary *)result; |
| | | //数据 |
| | |
| | | for (int i =0; i<ar.count; i++) { |
| | | [_dataAry addObject:[ar objectAtIndex:i]]; |
| | | } |
| | | |
| | | NSString *str2=[NSString stringWithFormat:@"pagenumberX%@Y%ldZ%ld",_Species,(long)SpeciesNumber,(long)typeNumber]; |
| | | NSString *pagenumber=[NSString stringWithFormat:@"%d",(int)(page+1)]; |
| | | //将获取到的数据存入字典中 |
| | |
| | | UITableView *tableView=[self.view viewWithTag:800+SpeciesNumber]; |
| | | [tableView.mj_header endRefreshing]; |
| | | [tableView.mj_footer endRefreshing]; |
| | | if (ar.count == 0) { |
| | | [tableView.mj_footer endRefreshingWithNoMoreData]; |
| | | } |
| | | [tableView reloadData]; |
| | | }else{ |
| | | UITableView *tableView=[self.view viewWithTag:800+SpeciesNumber]; |
| | |
| | | cell.SearchTabelViewTag.textColor=[UIColor grayColor]; |
| | | //加载名称 |
| | | cell.searchTableViewCellTitle.text=model.Name; |
| | | if([model.Name rangeOfString:@"一家两口"].location !=NSNotFound){ |
| | | NSLog(@"%@\n",model.Hpicture); |
| | | NSLog(@"%@",[_dataAry objectAtIndex:(indexPath.row)]); |
| | | |
| | | } |
| | | |
| | | //观看数量 |
| | | cell.searchTableViewCellWatchNUB.textColor=kGlobalLightGreyColor_210; |
| | | NSString *recommentStr; |
| | |
| | | return cell; |
| | | } |
| | | |
| | | #pragma mark -SDCycleScrollViewDelegate |
| | | /** 点击图片回调 */ |
| | | - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{ |
| | | if (self.CycleScrollData == nil || self.CycleScrollData.count<1) { |
| | | return; |
| | | } |
| | | if ([[_CycleScrollData objectAtIndex:index] objectForKey:@"Ad"]==nil) { |
| | | XYRDetailViewController *play=[[XYRDetailViewController alloc]init]; |
| | | play.Model = [XYRVideoInfoModel yy_modelWithDictionary:[self.CycleScrollData[index] objectForKey:@"VideoInfo"]]; |
| | | [self presentViewController:play animated:YES completion:^{ |
| | | |
| | | }]; |
| | | }else { |
| | | NSDictionary *dic=[[_CycleScrollData objectAtIndex:index]objectForKey:@"Ad"]; |
| | | [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[dic objectForKey:@"Link"]]]; |
| | | [[YTHNetInterface startInterface] UploadClickAD:[YTHsharedManger startManger].Uid WithSystem:@"1" withId:[dic objectForKey:@"Id"] WithPid:[dic objectForKey:@"Pid"] WithType:@"3" WithBlock:^(BOOL isSuccessful, id result, NSString *error) { |
| | | |
| | | }]; |
| | | } |
| | | } |
| | | |
| | | #pragma mark -UICollectionViewDataSource |
| | | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ |
| | |
| | | //如果是轮播图 |
| | | shufflingCollectionReusableView *shuffling=[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"shufflingCollectionReusableView" forIndexPath:indexPath]; |
| | | //定制轮播图 |
| | | [shuffling addSubview:_cycleScrollView]; |
| | | // [shuffling addSubview:_cycleScrollView]; |
| | | return shuffling; |
| | | |
| | | }else{ |
| | |
| | | self.nativeAdView=appInstallAdView; |
| | | } |
| | | |
| | | - (void)scrollViewDidScroll:(UIScrollView *)scrollView { |
| | | |
| | | if (scrollView.contentOffset.y<KScreenH/2) { |
| | | [self.topButton setHidden:YES]; |
| | | }else{ |
| | | [self.topButton setHidden:NO]; |
| | | } |
| | | } |
| | | #pragma mark -GADAdLoaderDelegate |
| | | /** |
| | | * 广告加载失败 |
| | |
| | | UITableView *tableView=[self.view viewWithTag:800+SpeciesNumber]; |
| | | [tableView reloadData]; |
| | | } |
| | | |
| | | - (void)dealloc{ |
| | | |
| | | } |
| | | |
| | | @end |