LNPopupController: Technique for dismissing TableView `contentViewController` onDrag
My content view controller’s primary view is a UIScrollView
subclass, specifically: UITableVIew
. Any advice on what the correct solution is for getting the popupInteractionGestureRecognizer
to work simultaneously with its installed panGestureRecognizer
so that if the scroll view’s contentOffset
is zero, dragging down will dismiss the content view controller?
I have a crude initial attempt, which looks in the tableView
’s gesture recognizer array for popupInteractionGestureRecognizer
. When the contentOffset
is just right ™, it will stop the panGestureRecognizer
from beginning.
It works…but not great.
Current attempt
private override func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
// Capture '_popupGesture', if necessary...
if (gestureRecognizers?.contains(gestureRecognizer) ?? false) == false
&& gestureRecognizer is UIPanGestureRecognizer
&& _popupGesture == nil {
_popupGesture = gestureRecognizer as? UIPanGestureRecognizer
} else if gestureRecognizer == panGestureRecognizer {
if let _ = _popupGesture {
switch (contentOffset.y + 44.0, panGestureRecognizer.velocityInView(self).y) {
case (-CGFloat.max...0, 1...CGFloat.max):
return false
default:
return true
}
}
}
return true
}
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 17 (11 by maintainers)
It works! Thank you
@MaxHasADHD Ha! It’s already supported out of the box. I checked my implementation. Just provide your scrollview as
viewForPopupInteractionGestureRecognizer
. Check the documentation and headers for more information.The controller I have to pop up is a UIViewController but has a UIScrollView as it’s main content view with a custom layout, so I can’t use UITableViewController or UICollectionViewController. How can I make the view controller drag down like in the demo with the scroll view?
@KevinVitale @joshluongo Implemented! Pull your scrollview based views (inc. tables views and collection views) to dismiss. Note, that you must have the content controller’s view be a scrollview based, so use
UITableViewController
,UICollectionViewController
, etc.