在我覆盖UICollectionViewFlowLayout
后,它会显示3个警告,如下所示
仅针对UICollectionViewFlowLayout缓存不匹配的框架记录一次
UICollectionViewFlowLayout
缓存了索引路径{length = 2,path = 0 - 1}的帧不匹配 - 缓存值:{{145,0},{130,130}};预期价值:{{5,141},{130,130}}
这可能是因为流布局子类FullyHorizontalFlowLayout正在修改UICollectionViewFlowLayout
返回的属性而不复制它们
我使用' FullyHorizontalFlowLayout
'使i单元格从左到右排列(原始是从上到下)。以下是我的layoutAttributesForElementsInRect
'代码
-(NSArray*)layoutAttributesForElementsInRect:(CGRect)rect
{
CGFloat newX = MIN(0, rect.origin.x - rect.size.width/2);
CGFloat newWidth = rect.size.width*2 + (rect.origin.x - newX);
CGRect newRect = CGRectMake(newX, rect.origin.y, newWidth, rect.size.height);
// Get all the attributes for the elements in the specified frame
NSArray *allAttributesInRect = [super layoutAttributesForElementsInRect:newRect];
for (UICollectionViewLayoutAttributes *attr in allAttributesInRect) {
UICollectionViewLayoutAttributes *newAttr = [self layoutAttributesForItemAtIndexPath:attr.indexPath];
attr.frame = newAttr.frame;
attr.center = newAttr.center;
attr.bounds = newAttr.bounds;
attr.hidden = newAttr.hidden;
attr.size = newAttr.size;
}
return allAttributesInRect;
}
答案 0 :(得分:0)
您应该使用以下片段深度复制支持属性数组:
Apple