Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AndreaMiotto opened this issue May 26, 2019 · 5 comments
Open

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

AndreaMiotto opened this issue May 26, 2019 · 5 comments

Comments

@AndreaMiotto
Copy link

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

@Alejandro99aru
Copy link

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.

@AndreaMiotto
Copy link
Author

AndreaMiotto commented May 26, 2019

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 }

		...
	}

@MarioIannotta
Copy link
Owner

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

AndreaMiotto added a commit to AndreaMiotto/PullUpController that referenced this issue Jun 3, 2019
@AndreaMiotto
Copy link
Author

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.

@jsafoan
Copy link

jsafoan commented Jul 8, 2019

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants