2023年7月14日发(作者:)
UICollectionView遇到的问题问题1问题描述:在做顶部弹窗的时候,UICollectionView有两个Section时,如果两个Section的宽度不⼀致。点击某个item,调⽤[tionView reloadData]时,会出现宽度错乱。⽬前解决⽅案:解决⼀:- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ if (n == 0) { return CGSizeMake(( - 70)/3, 36); }else{ return CGSizeMake(( - 55)/2, 36); }}if (n == 0) { model = ingDataSource[]; = CGRectMake(0, 0,( - 70)/3, 36); }else{ model = meDataSource[]; = CGRectMake(0, 0,( - 55)/2, 36); }解决⼆:设置UICollectionViewCell设置 sizingMask = UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight;- (instancetype)initWithFrame:(CGRect)frame{ if (self = [super initWithFrame:frame]) { ab = [[UILabel alloc]init]; lor = [UIColor darkTextColor]; = YNFont(14); ignment = NSTextAlignmentCenter; oundColor = YNRGB(238, 239, 242); [tView addSubview:ab];
= CGRectMake(0, 0, , );
sizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; } return self;}问题2UICollectionView有两个Section时,调⽤[tionView reloadData],会出现UICollectionView闪动。⽬前解决⽅案:刷新单个indexpath [tionView reloadItemsAtIndexPaths:@[indexPath]];
发布者:admin,转转请注明出处:http://www.yc00.com/news/1689265449a226467.html
评论列表(0条)