问题1
问题描述:在做顶部弹窗的时候,UICollectionView有两个Section时,如果两个Section的宽度不一致。点击某个item,调用[self.collectionView reloadData]时,会出现宽度错乱。
目前解决方案:
解决一:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 0) {
return CGSizeMake((self.frame.size.width - 70)/3, 36);
}else{
return CGSizeMake((self.frame.size.width - 55)/2, 36);
}
}
if (indexPath.section == 0) {
model = self.unLoadingDataSource[indexPath.row];
cell.titleLab.frame = CGRectMake(0, 0,(self.frame.size.width - 70)/3, 36);
}else{
model = self.workTimeDataSource[indexPath.row];
cell.titleLab.frame = CGRectMake(0, 0,(self.frame.size.width - 55)/2, 36);
}
解决二:
设置UICollectionViewCell设置 self.titleLab.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- (instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
self.titleLab = [[UILabel alloc]init];
self.titleLab.textColor = [UIColor darkTextColor];
self.titleLab.font = YNFont(14);
self.titleLab.textAlignment = NSTextAlignmentCenter;
self.titleLab.backgroundColor = YNRGB(238, 239, 242);
[self.contentView addSubview:self.titleLab];
self.titleLab.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
self.titleLab.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}
return self;
}
问题2
UICollectionView有两个Section时,调用[self.collectionView reloadData],会出现UICollectionView闪动。
目前解决方案:刷新单个indexpath
[self.collectionView reloadItemsAtIndexPaths:@[indexPath]];