Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 重写UICollectionViewFlowLayout后,对于缓存不匹配的帧,它只显示一次日志记录_Objective C_Xcode7_Ios9.2 - Fatal编程技术网

Objective c 重写UICollectionViewFlowLayout后,对于缓存不匹配的帧,它只显示一次日志记录

Objective c 重写UICollectionViewFlowLayout后,对于缓存不匹配的帧,它只显示一次日志记录,objective-c,xcode7,ios9.2,Objective C,Xcode7,Ios9.2,在我覆盖UICollectionViewFlowLayout之后,它会显示3条警告,如下所示 仅为UICollectionViewFlowLayout缓存记录一次不匹配的帧 UICollectionViewFlowLayout索引路径{length=2,path=0-1}的缓存帧不匹配-缓存值:{{145,0},{130,130};期望值:{5141},{130130} 这可能是因为流布局子类FullyHorizontalFlowLayout正在修改UICollectionViewFlowLa

在我覆盖
UICollectionViewFlowLayout
之后,它会显示3条警告,如下所示

  • 仅为UICollectionViewFlowLayout缓存记录一次不匹配的帧

  • UICollectionViewFlowLayout
    索引路径{length=2,path=0-1}的缓存帧不匹配-缓存值:{{145,0},{130,130};期望值:{5141},{130130}

  • 这可能是因为流布局子类FullyHorizontalFlowLayout正在修改
    UICollectionViewFlowLayout
    返回的属性,而不复制它们

我使用“
FullyHorizontalFlowLayout
”使i单元格从左到右排列(原始单元格是从上到下排列的)。下面是我的“
layouttributesforementsinrect
”代码

-(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;
}

您应该使用下面的片段深入复制support Attributes数组:

NSArray *superArray = [super layoutAttributesForElementsInRect:rect];
NSArray *array = [[NSArray alloc] initWithArray:superArray copyItems:YES];