Ios UICollectionViewCell重叠
我有一个水平滚动的UICollectionView,我正在使用UICollectionViewFlowLayout设置水平方向 当我使用以下命令删除其中一个单元格时—Ios UICollectionViewCell重叠,ios,uicollectionview,uicollectionviewcell,uicollectionviewlayout,Ios,Uicollectionview,Uicollectionviewcell,Uicollectionviewlayout,我有一个水平滚动的UICollectionView,我正在使用UICollectionViewFlowLayout设置水平方向 当我使用以下命令删除其中一个单元格时— [self.collectionView deleteItemsAtIndexPaths:selectedItemsIndexPaths]; 我注意到,在回滚到第一个UICollectionViewCell时(删除上述单元格时不可见),与第二个UICollectionViewCell重叠,如下所示 有时,它不是重叠,而是像-
[self.collectionView deleteItemsAtIndexPaths:selectedItemsIndexPaths];
我注意到,在回滚到第一个UICollectionViewCell时(删除上述单元格时不可见),与第二个UICollectionViewCell重叠,如下所示
有时,它不是重叠,而是像-
我的cellForItemAtIndexPath看起来像-
ABCollectionViewCell *cell = (ABCollectionViewCell *)[cv dequeueReusableCellWithReuseIdentifier:@"abCell" forIndexPath:indexPath];
cell.name.text = [self.categoryArray objectAtIndex:indexPath.row];
cell.contactButton.tag = indexPath.row;
cell.layer.cornerRadius = 5.0;
cell.layer.borderColor = [UIColor lightGrayColor].CGColor;
cell.layer.borderWidth = 1.0;
cell.clipsToBounds = YES;
return cell;
我已经在网上尝试了所有类似的问题解决方案,但似乎都不起作用。任何帮助都将不胜感激
UICollectionViewFlowLayout-
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
flowLayout.estimatedItemSize = CGSizeMake(102.0, 102.0);
flowLayout.minimumLineSpacing = 6.0f;
flowLayout.minimumInteritemSpacing = 2.0f;
[self.collectionView setCollectionViewLayout:flowLayout];
使用此功能
func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
insetForSectionAtIndex section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
}
像这样执行删除
[self.collectionView performBatchUpdates:^{
[self.collectionView deleteItemsAtIndexPaths:selectedItemsIndexPaths];
} completion:^{
[self.collectionView layoutIfNeeded];
}];
如何确定项的大小?-(CGSize)collectionView:(UICollectionView)collectionView布局:(UICollectionViewLayout)collectionViewLayout SizeFormiteIndeXPath:(NSIndexPath*)indexPath给出大小,因为单元格大小为dynamictry[self.collectionView reloadData];在完成区。仍然不工作。而且,仅当第一个单元格不可见时,才会发生这种情况。如果第一个单元格可见,则不会发生这种情况。