【问题标题】:Animating Collection View Cells in iOSiOS 中的集合视图单元格动画
【发布时间】:2013-11-04 21:32:47
【问题描述】:

当我的视图控制器的视图出现时,我希望其集合视图中的所有单元格水平翻转。

如何做到这一点?我查看了 UIDynamics 并没有找到翻转动画。我有一个使用 Core Animation 的动画,它会翻转视图,但我不知道如何将它应用于单元格。

【问题讨论】:

    标签: ios6 ios7 core-animation uicollectionview uicollectionviewcell


    【解决方案1】:

    您可以在 UICollectionViewFlowLayout 的子类中使用此方法:

    - (UICollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)itemIndexPath
    {
        UICollectionViewLayoutAttributes *layoutAttributes = [super initialLayoutAttributesForAppearingItemAtIndexPath:itemIndexPath];
    
        CATransform3D transform = CATransform3DMakeRotation(DEGREES_TO_RADIANS(180.0), 0.0, 1.0, 0.0);
    layoutAttributes.transform3D = transform;
    
        return layoutAttributes;
    }
    

    这基本上是抓取collectionViewCell 的初始布局属性并将其水平翻转。在插入单元格时,flowLayout 将从这些初始属性到该单元格的原始属性执行线性动画。如果您调用此方法将被调用

    - (void)performBatchUpdates:(void (^)(void))updates completion:(void (^)(BOOL finished))completion;
    

    并使用

    传递您的插入
    - (void)insertItemsAtIndexPaths:(NSArray *)indexPaths;
    

    进入更新块。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多