
添加了两个手势:
第一个(向上)将擦除单元格.
第二个(向下)将更新单元格(获取CoreData的新数据).
功能很好,但没有动画. iOS有一个非常酷的动画拖动单元格,单元格消失.
我很快就是动画的初学者,所以当它变得有点失落时.
我的问题是:如何添加占据整个单元格的动画?
我在网站上阅读了一些答案,但都是在Object-C(like this)中.
有人能帮我吗?
在UICollectionVIEw的单元格上实现动画的最佳方法是覆盖其布局UICollectionVIEwLayout.它的方法将返回您想要显示/插入/删除的单元格的布局属性.例如:我创建了一个继承UICollectionVIEwFlowLayout的类KDCollectionVIEwFlowLayout并覆盖了delete属性.
class KDCollectionVIEwFlowLayout: UICollectionVIEwFlowLayout { overrIDe func finalLayoutAttributesFordisappearingItemAtIndexPath(itemIndexPath: NSIndexPath) -> UICollectionVIEwLayoutAttributes? { let attribute = super.finalLayoutAttributesFordisappearingItemAtIndexPath(itemIndexPath) attribute?.transform = CGAffinetransformTranslate(attributes.transform,ITEM_SIZE) attribute?.Alpha = 0.0 return attribute }} 现在,您需要将此flowLayout的对象分配给vIEwDIDLoad中的集合视图,或者您可以通过storyboard分配它.
let flowLayout = KDCollectionVIEwFlowLayout()self.collectionVIEw?.setCollectionVIEwLayout(flowLayout,animated: true)
现在,无论何时对collectionVIEw执行任何删除 *** 作,都可以将您定义的单元格转换为finalLayoutAttributesFordisappearingItemAtIndexPath方法.
更新
您需要使用批处理 *** 作从集合视图中删除项目.
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中的Cell – Swift 2.0全部内容,希望文章能够帮你解决滑动动画以删除UICollectionView中的Cell – Swift 2.0所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)