【问题标题】:Warning in use custom collectionViewFlowLayot使用自定义 collectionViewFlowLayot 的警告
【发布时间】:2017-03-20 02:40:24
【问题描述】:

我只是修改了我的flowLayout中的属性

-(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
    NSMutableArray *array = [[super layoutAttributesForElementsInRect:rect] mutableCopy];

    for (int i = 0; i< array.count; i++) {
        UICollectionViewLayoutAttributes* attributes = array[i];
        if (!attributes.representedElementKind) {
            array[i] = [self layoutAttributesForItemAtIndexPath:attributes.indexPath];
        }
    }
    return array;
}

- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewLayoutAttributes *attributes = [super layoutAttributesForItemAtIndexPath:indexPath];
    CGFloat midX = self.collectionView.contentOffset.x + self.collectionView.width * 0.5;
    CGFloat distance = midX - attributes.center.x;
    CGFloat activeDistance = self.collectionView.width - lineSpacing - remainSpacing * 2;
    CGFloat normalizedDistance = distance / activeDistance;
    attributes.alpha = 1 - (1 - alphaFactor) * ABS(normalizedDistance);
    CGFloat zoom = 1 - (1 - scaleFactor) * ABS(normalizedDistance);
    attributes.transform3D = CATransform3DMakeScale(1.0, zoom, 1.0);
    attributes.zIndex = 1;
    return attributes;
}

这样的问题,第一次更改显示单元格时退出控制台:

UICollectionViewFlowLayout 缓存了索引路径 {length = 2, path = 0 - 1} 的帧不匹配 - 缓存值:{{350, 15.75}, {265, 283.5}};期望值:{{350, 0}, {265, 315}}

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

【问题讨论】:

    标签: objective-c uicollectionview flowlayout


    【解决方案1】:

    这样做,复制属性

    UICollectionViewLayoutAttributes *attributes = [[super layoutAttributesForItemAtIndexPath:indexPath] copy];
    

    这个问题在这个问题上已经解决了: Warning: UICollectionViewFlowLayout has cached frame mismatch for index path 'abc'

    【讨论】:

      猜你喜欢
      • 2020-06-30
      • 1970-01-01
      • 2012-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-12
      • 1970-01-01
      相关资源
      最近更新 更多