我展示了一个带有 uicollectionview 的 View Controller 。我希望单元格从顶部开始动画。
我的布局是flowlayout的一个子类,所以我覆盖了这个方法:
- (UICollectionViewLayoutAttributes *) initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewLayoutAttributes* attributes = [super initialLayoutAttributesForAppearingItemAtIndexPath:indexPath];
CGFloat height = [self collectionViewContentSize].height;
attributes.transform3D = CATransform3DMakeTranslation(0, -height, 0);
return attributes;
}
它几乎可以工作,但我看到单元格在动画进入之前会在屏幕上短暂出现(闪烁)。
知道为什么在应用转换之前它们会出现在最终位置吗?我可以如何防止这种情况发生?
最佳答案
与其设置变换,不如更改中心:
- (UICollectionViewLayoutAttributes *) initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewLayoutAttributes* attributes = [super initialLayoutAttributesForAppearingItemAtIndexPath:indexPath];
CGPoint c = attributes.center;
c.y -= self.collectionViewContentSize.height;
attributes.center = c;
return attributes;
}
更改转换总是会导致确定可见性出现问题,因为这样做会使 frame
属性无效。
关于ios - UICollectionView 最初为单元格设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17729802/