UICollectionViewFlowLayout doesn't use integral frames

后端 未结 1 2013
感动是毒
感动是毒 2021-02-06 16:58

I have recently started using UICollectionView, and am a bit confused about the UICollectionViewFlowLayout. It would seem that the frames for each cell in the collection view ar

1条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-06 17:53

    Workaround: subclass UICollectionViewFlowLayout, override UICollectionViewLayout's -layoutAttributesForElementsInRect: and for every layout attributes make the frame integral:

    - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
    {
        NSArray *allLayoutAttributes = [super layoutAttributesForElementsInRect:rect];
        for (UICollectionViewLayoutAttributes *layoutAttributes in allLayoutAttributes) {
            layoutAttributes.frame = CGRectIntegral(layoutAttributes.frame);
        }
        return allLayoutAttributes;
    }
    

    Note: iOS 7 UICollectionViewFlowLayout has been fixed to always use integral frames for its cells' frames. I recommend keeping the fix for iOS 6.x but conditionally deprecate it for iOS 7 and newer.

    Best, Raphael

    0 讨论(0)
提交回复
热议问题