I'm working with customizing tableViewCell.
I'm gonna make tableViewCell like Mail app in iOS.
When users swipe cells left or right way,
It shows button along with translation.
It's different with default like below.
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete{
self.allChatroomList.remove(at:indexPath.row)
self.tableView.reloadData()
}
}
So I'm working with UISwipeGesture but I can't get translation or position.
How can I get that?
rightDelete.frame = CGRect(x:UIScreen.main.bounds.width, y:0, width:50, height:71)
rightHide.backgroundColor = UIColor.red
addSubview(rightHide)
let leftSwipe = UIPanGestureRecognizer(target: self, action:#selector(self.swipe))
leftSwipe.delegate = self
mainView.isUserInteractionEnabled = true
self.mainView.addGestureRecognizer(leftSwipe)
func swipe(gesture: UIPanGestureRecognizer){
let translation = gesture.translationInView(self.view)
let swipeGesture:UISwipeGestureRecognizer = gesture as! UIpanGestureRecognizer
if(swipeGesture.direction == .left)
{
self.leftHide.centerX = self.leftHide.centerX + translation.x
self.leftDelete.centerX = self.leftDelete.centerX + translation.x/2
}
else if(swipeGesture.direction == .right)
{
}
}
}