Der beste Weg, um die Animation auf der Zelle von zu erreichen, ist das Überschreiben des Layouts UICollectionViewLayout
. Es hat Methode, die die Layoutattribute der Zelle zurückgibt, die Sie entweder anzeigen/einfügen/löschen möchten.
Zum Beispiel: Ich habe eine Klasse erstellt KDCollectionViewFlowLayout
erben UICollectionViewFlowLayout
und überschreiben das Attribut löschen.
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
}
}
Jetzt müssen Sie Aufgabe dieser Flow der Sammlung Ansicht in entweder viewDidLoad zuweisen oder Sie können es durch Storyboard zuweisen.
let flowLayout = KDCollectionViewFlowLayout()
self.collectionView?.setCollectionViewLayout(flowLayout, animated: true)
Nun Sie sind alle für die Transformation von Zellen festgelegt, die Sie sich in finalLayoutAttributesForDisappearingItemAtIndexPath
Methode definiert, wenn Sie einen Löschvorgang auf dem collectionView
auszuführen.
aktualisieren
Sie müssen die Elemente aus der Sammlung Ansicht mit der Batch-Betrieb löschen.
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)
James Ihre App sieht gut aus! –
James, hast du das jemals so gemacht, wie du es geplant hast? Sie möchten genau die gleiche Funktionalität in Swift implementieren. Würde gerne Ihre App sehen, wenn Sie auch arbeiten! –