UICollectionView setLayout:animated: not preserving zIndex

前端 未结 7 2092
既然无缘
既然无缘 2021-02-01 20:12

I\'ve noticed that when calling setLayout:animated in a UICollectionView to switch between two layouts, the currently visible cell doesn\'t adhere to t

7条回答
  •  不要未来只要你来
    2021-02-01 20:47

    Using @sampage & @grimfrog answers as a starting point, I was able to get a similar situation working

    - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)path
    {
        UICollectionViewLayoutAttributes* attributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:path];
        attributes.zIndex = path.item;
        attributes.transform3D = CATransform3DMakeTranslation(0, 0, path.item);
        // other attribute settings
        return attributes;
    }
    

    My layoutAttributesForElementsInRect: calls layoutAttributesForItemAtIndexPath: when generating the attribute array - so I only needed to include the zIndex and transform3D there.

提交回复
热议问题