做法:
通過改變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;
? ? }
}