刷卡动画在UICollectionView去除细胞 - 雨燕2.0 [英] Swipe Animation for remove Cell in UICollectionView - Swift 2.0

查看:526
本文介绍了刷卡动画在UICollectionView去除细胞 - 雨燕2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了 UICollectionView 应用程序这样的图片:

I created an app with UICollectionView like this image:

在这里输入的形象描述

增加了两个手势:

第一(上)将擦除单元。

The first (up) will erase the cell.

第二(下)将更新单元(以CoreData的新数据)。
功能做工精细,但没有动画。 iOS版有一个非常酷的动画拖动细胞和细胞消失。

The second (down) will update the cell (take new data of CoreData). The functions work fine, but there's no animation. iOS has a very cool animation dragging the cell up and the cell disappears.

我在动画迅速初学者,所以我有点失落,当它。

I am a beginner in animations swift, so I'm a little lost when it.

我的问题是:我如何添加动画,占用了整个单元

My question is: How can I add an animation that takes up the entire cell?

我看了网站上的一些答案,但所有的对象-C(<一个href=\"http://stackoverflow.com/questions/16742677/animation-time-of-uicollectionview-on-deletion-of-cell-in-ios\">like这)。

I read some answers on the site, but all in Object-C (like this).

有人能帮助我吗?

推荐答案

上实现 UICollectionView 的单元格中的动画覆盖其布局<$ C $的最佳方式C> UICollectionViewLayout 。它有方法将返回你想要么显示/插入/删除单元格的布局属性。

The best way to achieve the animation on the cell of UICollectionView is overriding its layout UICollectionViewLayout. Its has method which will return the layout attributes of the cell which you want to either appear/insert/delete.

例如:我创建了一个类 KDCollectionViewFlowLayout 继承 UICollectionViewFlowLayout 并覆盖删除属性。

For example: I created a class KDCollectionViewFlowLayout inheriting UICollectionViewFlowLayout and override the delete attribute.

class KDCollectionViewFlowLayout: UICollectionViewFlowLayout {

  override func finalLayoutAttributesForDisappearingItemAtIndexPath(itemIndexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
        let attribute = super.finalLayoutAttributesForDisappearingItemAtIndexPath(itemIndexPath)

        attribute?.transform = CGAffineTransformTranslate(attributes.transform, 0, ITEM_SIZE)
        attribute?.alpha = 0.0
        return attribute

    }
}

现在,你需要在任何viewDidLoad中指定此FlowLayout对象的集合视图或者您也可以通过故事板进行分配。

Now you need to assign object of this flowLayout to the collection view in either viewDidLoad or you can assign it through storyboard.

let flowLayout = KDCollectionViewFlowLayout()
self.collectionView?.setCollectionViewLayout(flowLayout, animated: true)

现在,你们都设置为细胞的转化,你中定义为 finalLayoutAttributesForDisappearingItemAtIndexPath 方法,只要你在的CollectionView

Now, you are all set for transformation of cell which you defined in to finalLayoutAttributesForDisappearingItemAtIndexPath method whenever you perform any delete operation on the collectionView.

更新

您需要删除使用批处理操作从集合视图中的项目。

You need delete the items from collection view using batch operation.

collectionView.performBatchUpdates({ () -> Void in
   //Array of the data which you need to deleted from collection view
    let indexPaths = [NSIndexPath]()
    //Delete those entery from the data base. 

    //TODO: Delete the information from database

    //Now Delete those row from collection View 

    collectionView.deleteItemsAtIndexPaths(indexPaths)

}, completion:nil)

这篇关于刷卡动画在UICollectionView去除细胞 - 雨燕2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆