Attaching a tableview, the swipe cell action doesn't work
Opened this issue · 5 comments
Hi, I'm using the pullUpController with a tableview that is attached with the proper func.
I really have the need to add edit cel action that is performed with the swipe. But apparently there is something with the pullUpController that is blocking the swipe gesture
Hi, I have the same problem. I have a table view inserted and it does not detect the click on the cell correctly, there is something that blocks it.
I've solved in this way:
in setupPanGestureRecognizer() in the PullUpViewController add the delegate to the gesture
private func setupPanGestureRecognizer() {
addInternalScrollViewPanGesture()
panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePanGestureRecognizer(_:)))
panGestureRecognizer?.minimumNumberOfTouches = 1
panGestureRecognizer?.maximumNumberOfTouches = 1
panGestureRecognizer?.delegate = self
if let panGestureRecognizer = panGestureRecognizer {
view.addGestureRecognizer(panGestureRecognizer)
}
}
than, always in the PullUpViewController file add this extension:
extension PullUpController: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
guard let _ = otherGestureRecognizer as? UIPanGestureRecognizer, let current = gestureRecognizer as? UIPanGestureRecognizer else {
return false
}
let velocity = current.velocity(in: self.view)
return abs(velocity.x) >= abs(velocity.y);
}
}
this allows multiple gestures simultaneously if:
- both gestures are pan;
- if the gesture is horizontal
You can modify the delegate as you prefer.
Than in the handlePanGestureRecognizer after the guard add this if statement, this prevents to scroll down the controller when you are doing a not so perfect horizontal swipe
@objc private func handlePanGestureRecognizer(_ gestureRecognizer: UIPanGestureRecognizer) {
guard
isPortrait,
let topConstraint = topConstraint
else { return }
let xVelocity = gestureRecognizer.velocity(in: self.view).x
let xTranslation = gestureRecognizer.translation(in: view).x
if abs(xVelocity) > 0 || abs(xTranslation) > 0 { return }
...
}
Hi @AndreaMiotto,
thanks for opening the issue and super thanks for providing the solution!
It would be great if you could provide a PR, I don't want to take credit for someone else work :)
Hi @AndreaMiotto,
thanks for opening the issue and super thanks for providing the solution!
It would be great if you could provide a PR, I don't want to take credit for someone else work :)
Thanks, added the pull request, please test it before the merge. Just use a table view as scroll view and add some swipe action to the cells.
Hi, I've added all the necessary changes listed above in my PullUpController, but it still doesn't recognize the swipe action gesture. Any idea as to what's going on?