I'm trying to implement an UISwipeGestureRecognizer in my collectionViewCell, so when you swipe to the left, the cell disappear. What i'm trying to implement (i can't find a way to do it) is to animate the swipe, so when i swipe the cell to the left, it disappears with a fade effect. This is the code i have inside the method cellForItemAtindexPath
let cSelector = #selector(reset(sender:))
let UpSwipe = UISwipeGestureRecognizer(target: self, action: cSelector)
UpSwipe.direction = UISwipeGestureRecognizerDirection.left
cell.addGestureRecognizer(UpSwipe)
The method
func reset(sender: UISwipeGestureRecognizer) {
let cell = sender.view as! UICollectionViewCell
let i = self.collectionView?.indexPath(for: cell)!.item
self.messages.remove(at: i!)
self.collectionView?.reloadData()
}
Thanks!!!
EDIT: I think i found an easiest way to do it, but i'm having some troubles. I tried implementing a UIPanGestureRecognizer in the cell. This is how it looks like...
cellForItemAt
let gestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePan(gestureRecognizer:)))
cell.addGestureRecognizer(gestureRecognizer)
The method
func handlePan(gestureRecognizer: UIPanGestureRecognizer) {
if gestureRecognizer.state == .began {
// When the drag is first recognized, you can get the starting coordinates here
}
if gestureRecognizer.state == .changed {
let translation = gestureRecognizer.translation(in: self.view)
// Translation has both .x and .y values
if translation.x == translation.x - 100 {
//Method i putted before
reset(sender: gestureRecognizer)
}
//print(translation.x, translation.y)
}
}
I'm trying to locate the coordinates of the cell, so when it's in a point at the left of the cell, the cell stars some kind of fade animation, and then disappear.
Any help??? Thanks!!!