0

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)
            {

            }

        }
    }
nikdange_me
  • 2,949
  • 2
  • 16
  • 24
kimpro
  • 107
  • 1
  • 2
  • 11
  • Possible duplicate of [Swift - add gesture recognizer to object in table cell](http://stackoverflow.com/questions/32290126/swift-add-gesture-recognizer-to-object-in-table-cell) –  Mar 03 '17 at 03:21
  • what do you want the code to execute it or please state issue you have!! – nikdange_me Mar 03 '17 at 17:25

0 Answers0