重写UICollectionLayout报错解决

报错

Logging only once for UICollectionViewFlowLayout cache mismatched frame

 UICollectionViewFlowLayout has cached frame mismatch for index path <NSIndexPath: 0xc000000001c00016> {length = 2, path = 0 - 14} - cached value: {{257, 748}, {100, 50}}; expected value: {{0, 714}, {100, 100}}

This is likely occurring because the flow layout subclass AMGrowFootFlowLayout is modifying attributes returned by UICollectionViewFlowLayout without copying them

解决

- (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect
{

    NSArray *orginal = [super layoutAttributesForElementsInRect:rect];
    NSArray *attrArr = [[NSArray alloc] initWithArray:orginal copyItems:YES];
    // 在这里面修改了UICollectionViewLayoutAttributes属性,必须操作对象副本,所以深拷贝一份。
    return attrArr;
}

你可能感兴趣的:(layout报错)