【发布时间】:2017-03-20 02:40:24
【问题描述】:
我只是修改了我的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 返回的属性而不复制它们
【问题讨论】:
标签: objective-c uicollectionview flowlayout