After I override UICollectionViewFlowLayout
it show 3 warning like below
Logging only once for UICollectionViewFlowLayout cache mismatched frame
UICollectionViewFlowLayout
has cached frame mismatch for index path {length = 2, path = 0 - 1} - cached value: {{145, 0}, {130, 130}}; expected value: {{5, 141}, {130, 130}}This is likely occurring because the flow layout subclass FullyHorizontalFlowLayout is modifying attributes returned by
UICollectionViewFlowLayout
without copying them
i use 'FullyHorizontalFlowLayout
' to make i cell arrange from left to right (original is from top to bottom). below is my 'layoutAttributesForElementsInRect
' code
-(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;
}
You should copy the support Attributes array deeply with the fragment below: