Wiered collectionView框架原点,如果变换180度

时间:2016-08-25 11:05:05

标签: ios uicollectionview uicollectionviewlayout cgaffinetransform

我通过代码

旋转180度
- (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;
}

CGRectMake框架

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

但我得到了

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

细胞从屏幕上消失。

如何正确旋转或将帧指定给x而不是中断和宽度?

1 个答案:

答案 0 :(得分:0)

我发现解决方案“不使用仿射变换”,而是使用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;
}

现在,一切都好。