PullUpController icon indicating copy to clipboard operation
PullUpController copied to clipboard

Attaching a tableview, the swipe cell action doesn't work

Open AndreaMiotto opened this issue 5 years ago • 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

AndreaMiotto avatar May 26 '19 09:05 AndreaMiotto

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.

Alejandro99aru avatar May 26 '19 09:05 Alejandro99aru

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 }

		...
	}

AndreaMiotto avatar May 26 '19 10:05 AndreaMiotto

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

MarioIannotta avatar May 30 '19 07:05 MarioIannotta

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.

AndreaMiotto avatar Jun 03 '19 13:06 AndreaMiotto

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?

jsafoan avatar Jul 08 '19 15:07 jsafoan