UICollectionView遇到的问题
问题1
问题描述:在做顶部弹窗的时候,UICollectionView有两个Section时,如果两个Section的宽度不⼀致。点击某个item,调⽤
[llectionView 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.w];
cell.titleLab.frame =CGRectMake(0,0,(self.frame.size.width -70)/3,36);
}else{
model =self.w];
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];
Color =[UIColor darkTextColor];
self.titleLab.font =YNFont(14);
Alignment = NSTextAlignmentCenter;
self.titleLab.backgroundColor =YNRGB(238,239,242);
[tView addSubview:self.titleLab];view ui框架
self.titleLab.frame =CGRectMake(0,0, frame.size.width, frame.size.height);
self.titleLab.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}
return self;
}
问题2
UICollectionView有两个Section时,调⽤[llectionView reloadData],会出现UICollectionView闪动。
⽬前解决⽅案:刷新单个indexpath
[llectionView reloadItemsAtIndexPaths:@[indexPath]];

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。