//
|
// liveTopicViewController.m
|
// BuWanVideo2.0
|
//
|
// Created by apple on 2017/6/7.
|
// Copyright © 2017年 com.yeshi.buwansheque.ios. All rights reserved.
|
//
|
|
#import "liveTopicViewController.h"
|
#import "WEBViewController.h"
|
#import "LiveListCollectionViewCell.h"
|
@interface liveTopicViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>{
|
int nowPage;//最新直播请求多少页
|
|
NSMutableArray *LiveData;
|
}
|
|
@end
|
|
@implementation liveTopicViewController
|
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
// Do any additional setup after loading the view from its nib.
|
|
//设置导航栏
|
[self createNavgationBar];
|
|
//创建列表
|
[self creatCollectionView];
|
}
|
|
/**
|
设置导航栏
|
*/
|
-(void)createNavgationBar{
|
self.view.backgroundColor=[UIColor whiteColor];
|
//设置账号登录的字体样式
|
self.navigationController.navigationBar.titleTextAttributes =@{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor blackColor]};
|
//设置返回按钮
|
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
|
[button setImage:[[UIImage imageNamed:@"详情页面返回"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
|
[button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
|
button.frame = CGRectMake(0, 0, 32, 32);
|
UIBarButtonItem *iconBarItem=[[UIBarButtonItem alloc] initWithCustomView:button];
|
self.navigationItem.leftBarButtonItem = iconBarItem;
|
}
|
|
/**
|
创建列表
|
*/
|
-(void)creatCollectionView{
|
_liveTopic.delegate=self;
|
_liveTopic.dataSource=self;
|
|
UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
|
//指定布局方式为垂直
|
flow.scrollDirection = UICollectionViewScrollDirectionVertical;
|
flow.minimumLineSpacing = 10;//最小行间距(当垂直布局时是行间距,当水平布局时可以理解为列间距)
|
flow.minimumInteritemSpacing = 8;//两个单元格之间的最小间距
|
|
[_liveTopic setCollectionViewLayout:flow];
|
|
//注册瀑布流的cell
|
[_liveTopic registerNib:[UINib nibWithNibName:@"LiveListCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"LiveListCollectionViewCell"];
|
|
//隐藏滚动条
|
_liveTopic.showsVerticalScrollIndicator=NO;
|
_liveTopic.showsHorizontalScrollIndicator=NO;
|
|
//设置背景色为透明
|
_liveTopic.backgroundColor=[UIColor clearColor];
|
|
_liveTopic.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
nowPage=1;
|
[self loadData];
|
}];
|
|
_liveTopic.mj_footer=[MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
|
[self loadData];
|
}];
|
}
|
|
-(void)setTitleStr:(NSString *)titleStr{
|
_titleStr=titleStr;
|
self.navigationItem.title = _titleStr;
|
}
|
|
-(void)setType:(NSString *)type{
|
_type=type;
|
nowPage = 1;
|
[self loadData];
|
}
|
|
-(void)loadData{
|
[[YTHNetInterface startInterface] getLiveListByTypeWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" WithType:_type withPage:[NSString stringWithFormat:@"%d",nowPage] WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
if (nowPage==1) {
|
LiveData=[[result objectForKey:@"Data"] objectForKey:@"data"];
|
}else{
|
NSArray *tempArr=[[result objectForKey:@"Data"] objectForKey:@"data"];
|
[LiveData addObjectsFromArray:tempArr];
|
}
|
|
++nowPage;
|
|
//刷新
|
[_liveTopic reloadData];
|
|
//结束上拉和下拉
|
[_liveTopic.mj_header endRefreshing];
|
[_liveTopic.mj_footer endRefreshing];
|
|
}else{
|
NSLog(@"网络连接失败!");
|
}
|
}];
|
}
|
|
|
/**
|
* 退出
|
*/
|
-(void)back{
|
[self.navigationController popViewControllerAnimated:YES];
|
}
|
|
- (void)didReceiveMemoryWarning {
|
[super didReceiveMemoryWarning];
|
// Dispose of any resources that can be recreated.
|
}
|
|
#pragma mark -UICollectionViewDataSource
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
return LiveData.count;
|
}
|
|
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
NSDictionary *tempDic=LiveData[indexPath.row];
|
LiveListCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"LiveListCollectionViewCell" forIndexPath:indexPath];
|
|
NSString *PicStr=[tempDic objectForKey:@"HeadPic"];
|
PicStr=[PicStr stringByReplacingOccurrencesOfString:@"100_100"withString:@"300_300"];
|
[cell.image setYthImageWithURL:PicStr placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
|
cell.name.text=[tempDic objectForKey:@"Name"];
|
cell.numPeople.text=[NSString stringWithFormat:@"%@人在观看",[tempDic objectForKey:@"LiveNum"]];
|
|
//添加阴影
|
cell.layer.masksToBounds = NO;
|
cell.layer.contentsScale = [UIScreen mainScreen].scale;
|
cell.layer.shadowOpacity = 0.7f;
|
cell.layer.shadowRadius = 1.0f;
|
cell.layer.shadowOffset = CGSizeMake(0,2);
|
cell.layer.shadowPath = [UIBezierPath bezierPathWithRect:cell.bounds].CGPath;
|
cell.layer.shadowColor = kGlobalLightGreyColor_223.CGColor;
|
//设置缓存
|
cell.layer.shouldRasterize = YES;
|
//设置抗锯齿边缘
|
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
|
|
return cell;
|
}
|
|
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
|
return 1;
|
}
|
#pragma mark -UICollectionViewDelegate
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
WEBViewController *webVC=[[WEBViewController alloc] init];
|
webVC.url=[LiveData[indexPath.row] objectForKey:@"H5Url"];
|
webVC.orMake=UIInterfaceOrientationMaskPortrait;
|
[self presentViewController:webVC animated:YES completion:^{
|
|
}];
|
}
|
|
#pragma mark -UICollectionViewDelegateFlowLayout
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
|
return CGSizeMake((KScreenW-8)/2-1, (KScreenW-8)/2+40);
|
}
|
|
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
|
return UIEdgeInsetsMake(0, 0, 0, 0);//分别为上、左、下、右
|
}
|
|
@end
|