首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >UICollectionviewCell动画

UICollectionviewCell动画
EN

Stack Overflow用户
提问于 2016-07-18 11:09:58
回答 2查看 2K关注 0票数 0

我想动画的集合视图单元格,动画应该是这样的:

第一个单元出现,在一些延迟之后,第二个单元将与一些动画一起出现,对于所有的单元格都是这样。

如何做到这一点?

EN

回答 2

Stack Overflow用户

发布于 2016-07-18 11:31:56

解决方案是增量地创建数据源,以便在设置时间延迟后添加一个单元格。一旦添加,插入

拨打一个电话,设置一个计时器,以添加到您的dataSource中,无论您喜欢什么延迟。

代码语言:javascript
运行
复制
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(addToDataSource:) userInfo:nil repeats:YES];

然后,在这个方法中,每隔0.05秒(在本例中)

代码语言:javascript
运行
复制
-(void)addToDataSource:(NSTimer*)timer{

    [self.yourMutableDataSourceArray addObject:OBJECT]

    NSInteger arrayCount = self.yourMutableDataSourceArray.count;

        [self.collectionView performBatchUpdates:^{
            [self.collectionView insertItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:arrayCount-1 inSection:0]]];
        } completion:^(BOOL finished) {

        }];

    //Once you have reached the desired count cells you wish, remember to invalidate the timer

}

performBatchUpdate将意味着collectionView将重新加载动画。

我希望这能帮到你

这是在objective中,但是如果你用快速的方式写这篇文章,同样的原则也适用。

票数 1
EN

Stack Overflow用户

发布于 2016-07-18 17:26:26

这里的另一个解决方案是使用willDisplayCell:forIndexPath委托。

这是我怎么做的一个例子。

代码语言:javascript
运行
复制
func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
    if (!loadedIdx.contains(indexPath.row)) {
        let cellContent = cell
        let rotationAngleDegrees : Double = -30
        let rotationAngleRadians = rotationAngleDegrees * (M_PI/180)
        let offsetPositioning = CGPoint(x: collectionView.bounds.size.width, y: -20)
        var transform = CATransform3DIdentity
        transform = CATransform3DRotate(transform, CGFloat(rotationAngleRadians), -50, 0, 1)
        transform = CATransform3DTranslate(transform, offsetPositioning.x, offsetPositioning.y, -50)

        cellContent.layer.transform = transform
        cellContent.layer.opacity = 0.2

        let delay = 0.06 * Double(indexPath.row)
        UIView.animateWithDuration(0.8, delay:delay , usingSpringWithDamping: 0.8, initialSpringVelocity: 0.5, options: .CurveEaseIn, animations: { () -> Void in
            cellContent.layer.transform = CATransform3DIdentity
            cellContent.layer.opacity = 1
        }) { (Bool) -> Void in

        }

        loadedIdx.append(indexPath.row)
    }

}

loadedIdx是一个数组,用于标记单元格为加载(下一次出现时不显示动画)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38435196

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档