UICollectionView setLayout:animated: not preserving zIndex

前端 未结 7 1983
既然无缘
既然无缘 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:39

    Try:

    // In UICollectionViewCell subclass
    - (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
    {
        [super applyLayoutAttributes:layoutAttributes];
        // Setting zPosition instead of relaying on
        // UICollectionView zIndex management 'fixes' the issue
        self.layer.zPosition = layoutAttributes.zIndex;
    }
    

提交回复
热议问题