Search code examples
iosuicollectionviewuicollectionviewlayoutcgaffinetransform

Wiered collectionView frame origin if transform 180 degres


I make rotation by 180 degrees by code

- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewLayoutAttributes *retAttr = [[super layoutAttributesForItemAtIndexPath:indexPath] copy];

    if (CGAffineTransformIsIdentity(retAttr.transform)) {
        retAttr.transform = CGAffineTransformMakeRotation(M_PI);
    }

    retAttr.frame = CGRectMake(0, retAttr.frame.origin.y, self.collectionView.bounds.size.width, retAttr.frame.size.height);
    return retAttr;
}

Frame by CGRectMake

(origin = (x = 0, y = 3658), size = (width = 320, height = 1077.5))

But i got

(lldb) po retAttr.frame
(origin = (x = -0.000000000000056843418860808015, y = 3658), size = (width = 320.00000000000011, height = 1077.5))

And cell disappear from screen.

How to correctly rotate or assign frame to x not breaks and width too?


Solution

  • I found solution "not use affine transform", instead this i use 3dTransform

    - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {
        UICollectionViewLayoutAttributes *retAttr = [[super layoutAttributesForItemAtIndexPath:indexPath] copy];
    
        if (CATransform3DIsIdentity(retAttr.transform3D)) {
            retAttr.transform3D = CATransform3DMakeRotation(M_PI, 0, 0, 1);
        }
    
        return retAttr;
    }
    

    Now, all ok.