复用的效果: 如图上下滑动的时候图片间距发生了变化
解决办法:
1、自定义cell中添加一个属性 ;
@property (nonatomic, assign) CGFloat height;
2、实现setter方法
- (void)setHeight:(CGFloat )height {
_height = height;
_itemIcon.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.height);
}
3、在viewController中
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CollModel * model = self.modelArray[indexPath.row];
CollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:moreImageC forIndexPath:indexPath];
cell.height = [self.heightArray[indexPath.row] floatValue];
cell.itemModel = model;
return cell;
}
以上就会解决复用界面混乱问题