我只修改了flowLayout中的属性
-(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
NSMutableArray *array = [[super layoutAttributesForElementsInRect:rect] mutableCopy];
for (int i = 0; i< array.count; i++) {
UICollectionViewLayoutAttributes* attributes = array[i];
if (!attributes.representedElementKind) {
array[i] = [self layoutAttributesForItemAtIndexPath:attributes.indexPath];
}
}
return array;
}
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewLayoutAttributes *attributes = [super layoutAttributesForItemAtIndexPath:indexPath];
CGFloat midX = self.collectionView.contentOffset.x + self.collectionView.width * 0.5;
CGFloat distance = midX - attributes.center.x;
CGFloat activeDistance = self.collectionView.width - lineSpacing - remainSpacing * 2;
CGFloat normalizedDistance = distance / activeDistance;
attributes.alpha = 1 - (1 - alphaFactor) * ABS(normalizedDistance);
CGFloat zoom = 1 - (1 - scaleFactor) * ABS(normalizedDistance);
attributes.transform3D = CATransform3DMakeScale(1.0, zoom, 1.0);
attributes.zIndex = 1;
return attributes;
}
这样的问题,控制台在第一次更改显示的单元格时注销:
UICollectionViewFlowLayout缓存了索引路径{length = 2,path = 0 - 1}的帧不匹配 - 缓存值:{{350,15.75},{265,283.5}};预期值:{{350,0},{265,315}}
这可能是因为流布局子类MyFlowLayout正在修改UICollectionViewFlowLayout返回的属性而不复制它们
答案 0 :(得分:1)
这样做,复制属性
UICollectionViewLayoutAttributes *attributes = [[super layoutAttributesForItemAtIndexPath:indexPath] copy];
此问题在此问题中已解决: Warning: UICollectionViewFlowLayout has cached frame mismatch for index path 'abc'