UICollectionView
की सेल अपने लेआउट UICollectionViewLayout
अधिभावी है पर एनीमेशन प्राप्त करने के लिए सबसे अच्छा तरीका है। इसकी विधि है जो उस सेल के लेआउट विशेषताओं को वापस कर देगी जिन्हें आप या तो दिखाना/डालना/हटाना चाहते हैं।
उदाहरण के लिए: मैंने KDCollectionViewFlowLayout
को UICollectionViewFlowLayout
विरासत में मिला और हटाए गए गुण को ओवरराइड किया।
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
}
}
अब आप संग्रह को देखने के लिए इस flowLayout की वस्तु आवंटित करने के लिए या तो viewDidLoad में की जरूरत है या आप स्टोरीबोर्ड के माध्यम से प्रदान कर सकते हैं।
let flowLayout = KDCollectionViewFlowLayout()
self.collectionView?.setCollectionViewLayout(flowLayout, animated: true)
अब, आप सभी सेल के परिवर्तन जो आप finalLayoutAttributesForDisappearingItemAtIndexPath
विधि के लिए में परिभाषित किया गया है जब भी आप collectionView
पर किसी भी हटाने की कार्रवाई को पूरा करने के लिए सेट कर रहे हैं।
अद्यतन
आप बैच आपरेशन का उपयोग कर संग्रह को देखने से आइटम हटाते हैं की जरूरत है।
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)
जेम्स आपका ऐप शानदार दिखता है! –
जेम्स, क्या आपने कभी यह काम किया है जैसा आपने इरादा किया था? स्विफ्ट में बिल्कुल उसी प्रकार की कार्यक्षमता को लागू करना चाहते हैं। अगर आप भी काम कर रहे हैं, तो अपने ऐप को देखना अच्छा लगेगा! –