使用自定义集合中的警告ViewFlowLayot



我只是修改我的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 返回的属性而不复制它们

像这样复制属性

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

这个问题在这个问题上已经解决了:警告:UICollectionViewFlowLayout 缓存了索引路径"abc"的帧不匹配

相关内容

  • 没有找到相关文章

最新更新