I want to drag the cell out of screen in left direction to delete it. I don't want to show the delete option of table view edit mode. Showing delete option is very old and traditional method thats why I want to do this with the help of gestures.
Asked
Active
Viewed 73 times
-4
-
Refer this [link](https://stackoverflow.com/questions/3309484/uitableviewcell-show-delete-button-on-swipe) – Aditya Srivastava Aug 14 '17 at 10:36
-
1Possible duplicate of [UITableViewCell, show delete button on swipe](https://stackoverflow.com/questions/3309484/uitableviewcell-show-delete-button-on-swipe) – Idan Aug 14 '17 at 10:37
1 Answers
1
Add this to you program:
let recognizer = UIPanGestureRecognizer(target: self, action: Selector(("handlePan")))
recognizer.delegate = self
addGestureRecognizer(recognizer)
And then make method to use this recognizer:
func handlePan(recognizer: UIPanGestureRecognizer) {
if recognizer.state == .began {
originalCenter = center
}
if recognizer.state == .changed {
let transition = recognizer.translation(in: self)
center = CGPoint(x: originalCenter.x + transition.x, y: originalCenter.y)
deleteOnDragRelease = frame.origin.x < -frame.size.width / 2.0
}
if recognizer.state == .ended {
let originalFrame = CGRect(x: 0, y: frame.origin.y, width: bounds.size.width, height: bounds.size.height)
if !deleteOnDragRelease {
UIView.animate(withDuration: 0.2, animations: {self.frame = originalFrame})
}
if deleteOnDragRelease {
if delegate != nil && toDoItem != nil {
delegate!.toDoItemDeleted(todoitem: toDoItem!)
}
}
}
}
i think you can get all your answers for this doubt on the link given below:

Vivek Tyagi
- 168
- 1
- 4
- 15
-
-
-
Hi AXY, their is second part also in it it can give you full picture of gesture on tableview cell – Vivek Tyagi Aug 16 '17 at 13:22