I have a PanGestureRecognizer
set on a child view controller's container view. This is essentially a drawer view, so I want the child view controller to handle any scrolls, except for when the child view controller's table view is scrolled to the top and the user pans down. In this case, I want the container view gesture recogniser to take over so the child view controller as a whole can be animated down. I have a delegate for the gesture recogniser and this works perfectly if, instead of a child view controller and container view, it is just a table view and I add the pan gesture recogniser to that. The way it is now though, the delegate is returning true when it should be, yet the handlePan method is not being called? Any ideas would be appreciated. Thanks!
All of the below code is in the parent UIViewController
that has a container view, which I am applying the gesture recogniser to. Everything displays correctly, just the gesture recogniser method is not called, but the delegate is.
func setUpItemDetailsController() {
guard let itemDetailsController = itemDetailsController else { return }
add(itemDetailsController)
itemDetailsContainerView.addSubview(itemDetailsController.view)
let panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePan))
panGestureRecognizer.delegate = self
itemDetailsContainerView.addGestureRecognizer(panGestureRecognizer)
}
@objc func handlePan(_ sender: UIPanGestureRecognizer) {
...
}
extension MoverScanAndDiscoverResultController: UIGestureRecognizerDelegate {
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
guard let panGestureRecognizer = gestureRecognizer as? UIPanGestureRecognizer else { return true }
let translation = panGestureRecognizer.translation(in: view).y
let topLimit = view.bounds.height - self.statusAndNavBarCombinedHeight
print(itemDetailsTableView.contentOffset.y)
// Allows for normal UITableView scrolling
if translation < 0
&& resultCardViewBottomConstraint.constant == topLimit
|| itemDetailsController?.tableView.contentOffset.y ?? 0 > 0 {
return false
}
return true
}
}