【问题标题】:After override UICollectionViewFlowLayout it shows logging only once for a cache mismatched frame覆盖 UICollectionViewFlowLayout 后,它只显示一次缓存不匹配帧的日志记录
【发布时间】:2016-02-24 04:28:52
【问题描述】:

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

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

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

  • 这可能是因为流布局子类FullyHorizo​​ntalFlowLayout 正在修改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;
}

【问题讨论】:

    标签: objective-c xcode7 ios9.2


    【解决方案1】:

    您应该使用下面的片段深入复制支持属性数组:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-13
      • 1970-01-01
      • 2012-01-12
      • 2014-03-17
      • 2022-01-27
      • 2014-04-17
      • 2016-04-27
      • 1970-01-01
      相关资源
      最近更新 更多