lukagabric/LGLinearFlow

when scrolling very fast, the newly appearing item first is big, then becomes small

haemi opened this issue · 3 comments

haemi commented

when scrolling through the elements very fast, the item that newly appears at the border of the screen first has the standard size for a very small amount of time and only then gets transformed smaller.

bump i cannot find an answer to this problem, plus once the cell becomes a certain size, the spacing between teh cells grow so only one is visible at a time on screen

so anyone find an answer?

For posterity, I fixed this by adding the following method:

- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
    //attributes are copied so that the collection view doesn't gripe about us modifying existing attribute objects
    UICollectionViewLayoutAttributes *attributes = [[super layoutAttributesForItemAtIndexPath:indexPath] copy];
    
    CGRect visibleRect = (CGRect){self.collectionView.contentOffset, self.collectionView.bounds.size};
    CGFloat visibleCenterX = CGRectGetMidX(visibleRect);
    
    CGFloat distanceFromCenter = visibleCenterX - attributes.center.x;
    CGFloat absDistanceFromCenter = MIN(ABS(distanceFromCenter), kScalingOffset);
    CGFloat scale = absDistanceFromCenter * (kMinimumScaleFactor - 1) / kScalingOffset + 1;
    
    attributes.transform3D = CATransform3DScale(CATransform3DIdentity, scale, scale, 1);
    
    return attributes;
}

It performs the same operations as - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect but is able to apply attributes to cells before they enter the visible rect.