做法:
通过改变UIcollectionviewFlowLayout 布局,完成切换
// 列表和网格切换
-(void)switchGoodsListType{
if (isPermutation) { // collectionview 样式
isPermutation = NO;
_flowLayout.itemSize=CGSizeMake(171*unitPX,275*unitPX);
_flowLayout.minimumLineSpacing=10*unitPX; // 行间距
_flowLayout.minimumInteritemSpacing = 10*unitPX; // 列间距
_flowLayout.sectionInset = UIEdgeInsetsMake(10*unitPX, 10*unitPX, 10*unitPX, 10*unitPX); // 上左下右
_goodsListCollectionView.collectionViewLayout = _flowLayout;
}else{ // tableview 样式
isPermutation = YES;
_flowLayout.itemSize=CGSizeMake(SCREEN_WIDTH,130*unitPX);
_flowLayout.minimumLineSpacing =0;
_flowLayout.minimumInteritemSpacing = 0;
_flowLayout.sectionInset = UIEdgeInsetsMake(10, 0, 10, 0);
_goodsListCollectionView.collectionViewLayout = _flowLayout;
}
[_goodsListCollectionView reloadData];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
if (isPermutation) {
PHGoodsTableListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:__goodsListTableCell forIndexPath:indexPath];
cell.backgroundColor = [UIColor whiteColor];
returncell;
}else{
PHGoodsListCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:__goodsListCollectionCell forIndexPath:indexPath];
cell.backgroundColor = [UIColor whiteColor];
returncell;
}
}