ios - UICollectionView 最初为单元格设置动画

标签 ios animation transform uicollectionview

我展示了一个带有 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/

相关文章:

ios - 适用于 iOS 的 Podofo;写入PDF文件后 "Catalog object not found"

ios - 如何处理正在加载的图像? swift

r - 将不同大小的行变成列

html - 将(CSS 旋转)元素与其容器的左侧对齐 - HTML/CSS

javascript - SVG 动画,其中波峰/波浪路径通过 javascript 变成波谷/山谷

CSS3 倾斜所有 Angular 落

带有游戏中心的 iPhone 应用程序

ios - 自从向文本添加语音(语音识别)以来,文本到语音的音量显着下降

android - 使用底部导航栏的 Intent 时淡入淡出幻灯片动画

javascript - 图像转换 jquery