問題描述
如何為collectionviewcell的刪除自定義動畫? (How to custom animation for collectionviewcell's deletion?)
默認collectionview deleteItems 會淡出單元格,我想改變這個動畫讓單元格像Tinder app 一樣飛出屏幕。請幫助
self.collectionView.performBatchUpdates({
self.likedArrayData?.append(self.arrayData![indexPath.item])
self.arrayData?.remove(at: indexPath.item)
self.collectionView.deleteItems(at:[indexPath])
}, completion: { [unowned self] (_) in
})
參考解法
方法 1:
let cell = self.collectionView!.cellForItem(at: indexPath)
UIView.animate(withDuration: 0.5, animations: {
cell?.center.y ‑= 500 // Move up 500 pixels
cell?.alpha = 0.0 //the cell will come back from top so I set al[ha to 0.0
}, completion: { () in
self.collectionView.performBatchUpdates({
self.likedArrayData?.append(self.arrayData![indexPath.item])
self.arrayData?.remove(at: indexPath.item)
self.collectionView.deleteItems(at:[indexPath])
}, completion: { [unowned self] () in
})
})
</code></pre>
(by Sen‑He Lee、Sen‑He Lee)
參考文件