<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
- (UICollectionView *)collectionView{
if (_collectionView == nil) {
UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
_collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:layout];
_collectionView.backgroundColor =[UIColor clearColor];
[_collectionView registerClass:[BlocVideoViewCell class] forCellWithReuseIdentifier:BLOC_TAG_VIDEO_CELL];
MJRefreshNormalHeader * header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
if (self.refreshBlock) {
self.refreshBlock();
}
}];
_collectionView.mj_header = header;
MJRefreshAutoNormalFooter * footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
if (self.loadMoreBlock) {
self.loadMoreBlock();
}
}];
_collectionView.mj_footer = footer;
}
_collectionView.delegate = self;
_collectionView.dataSource = self;
return _collectionView;
}
#pragma mark -UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return self.dataArray.count;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
WS(weakSelf);
BlocVideoViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:BLOC_TAG_VIDEO_CELL forIndexPath:indexPath];
cell.pushIndexToVideoPlayerBlock = ^(NSInteger index){
[weakSelf handelIntoVideoVC:index];
};
BlocVideoModel * videoMode = [self.dataArray objectAtIndex:indexPath.row];
[cell loadVideoData:videoMode withIndex:indexPath.row];
// cell.layer.borderColor = [[UIColor redColor]CGColor];
// cell.layer.borderWidth = 1;
// cell.backgroundColor = [UIColor greenColor];
return cell;
}
- (void)handelIntoVideoVC:(NSInteger )index{
BlocVideoModel * dataModel = [self.dataArray objectAtIndex:index];
if (self.pushToVideoPlayerBlock) {
self.pushToVideoPlayerBlock(dataModel);
}
// NSLog(@"cellbloc传的第几个-->%zd",index);
}
#pragma mark -UICollectionViewDelegateFlowLayout
//设置每个单元格的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
NSInteger columnsNum = 2;
NSInteger collectionViewWidth = self.collectionView.bounds.size.width;
CGFloat itemWidth =(collectionViewWidth -14-18*BLOC_W_ADJUST* (columnsNum -1))/columnsNum;
// NSLog(@"cell的宽--%f,collectionViewWidth宽-->%ld",itemWidth,(long)collectionViewWidth);
return CGSizeMake(itemWidth, 100*BLOC_H_ADJUST);
}
//设置纵向的行间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
return 0;
}
//设置单元格间的横向间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
return 18*BLOC_W_ADJUST;
}
////通过调整inset使单元格顶部和底部都有间距(inset次序: 上,左,下,右边)
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
return UIEdgeInsetsMake(0, 7, 0, 7);
}
#pragma mark -UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
BlocVideoModel * dataModel = [self.dataArray objectAtIndex:indexPath.row];
if (self.pushToVideoPlayerBlock) {
self.pushToVideoPlayerBlock(dataModel);
}
// NSLog(@"dijihang-->%zd",indexPath.row);
}
、、-----------------
在cell的 contentView中添加view
[self.contentView addSubview:self.videoBack];
[self.contentView addSubview:self.personLabel];