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
How to drag down the screen with horizontal Collection View? #214
Comments
Could you please post an example project? This should already work automatically; when you scroll to the top and pull the scroll view more, it should close the popup. |
Please take a look at this project: It seems that drag-down gesture is not working when collectionView is not moving, if you start dragging collectionView you can drag down entire view. |
Are you using a |
Ohhh, you have a horizontal collection. Sorry, I missed that. |
I'm having the exact same issue and playing around with Another project where that's reproducible in case it helps: |
@LeoNatan any news? Maybe point me in the right direction and I could try to fix it and create a PR but everything I've tried so far hasn't worked |
Hello, The solution, I imagine, would be to play around with the delegate. Take a look at: My guess is you'll have to determine the interaction type ("vertical pan") and the scroll view type ("horizontal scroll view") and return |
The weird thing is that when I do this
And I do this inside
I'm getting |
Looking at the library's code, it's only forwarding
|
I can't figure it out, as far as I understand it should work with a combination of
|
It might not be forwarded to the delegate. Try doing that in the actual delegate (not the forwarded user delegate), just to see if it works. |
I tried doing this inside the library with no luck (it's never calling
|
I tried running your example, and it works as expected. I also made a horizontal scrolling content view controller, and it seems to me to work as expected. |
If you can, please record a short video of your problem so I can understand how to test. Thanks |
The thing is we can't drag down from where the horizontal scrollView is (in the example represented by the blue and yellow views as its content). Also when returning |
@LeoNatan Does that gif show the issue? |
I'm not sure. It's not what I saw when I rand your project. I will look again during the weekend. Thanks |
Great! If it's worth something this happens both with |
@LeoNatan sorry for insisting but could you check? |
Sorry, no time at the moment |
Apple should ask which gesture recognizer to use! |
Hey @iDevelopper could you work around this in the past? I saw another issue where you were talking about something similar to this |
@DantePuglisi , which issue? |
There you played around with |
This a very old issue. It was my mistake when I wanted to set the delegate of the gesture with the wrong popupContentView. |
Try something like this: import UIKit
import LNPopupController
class TESTViewController: UIViewController {
@IBOutlet weak var scrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
}
}
extension TESTViewController: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: UIGestureRecognizer) -> Bool {
if let pgr = gestureRecognizer as? UIPanGestureRecognizer {
let velocity = pgr.velocity(in: view)
if velocity == .zero {
return true
}
else {
if abs(velocity.x) > abs(velocity.y) {
print("panning right or left")
return true
}
else {
print("panning up or down")
let page = Int((scrollView.contentOffset.x + (0.5 * scrollView.frame.size.width))/scrollView.frame.width)
let offset = page * Int(scrollView.frame.size.width)
scrollView.contentOffset.x = CGFloat(offset)
return false
}
}
}
return false
}
} import UIKit
import LNPopupController
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func showBarTapped(_ sender: Any) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
guard let vc = storyboard.instantiateViewController(withIdentifier: "TESTViewController") as? TESTViewController else {
return
}
popupContentView.popupInteractionGestureRecognizer.delegate = vc
popupContentView.popupCloseButtonStyle = .chevron
popupInteractionStyle = .drag
vc.popupItem.title = "Title"
vc.popupItem.subtitle = "Subtitle"
vc.popupItem.progress = 0.34
presentPopupBar(withContentViewController: vc, animated: true, completion: nil)
}
} |
Thanks @iDevelopper that works! It's a pretty smart solution 👏 The only thing (that maybe can't be fixed) is that I have to pan down too much for the viewcontroller to start dismissing, how you faced that as well? |
That makes sense, since you are waiting for the pan gesture recognizer to fail. What happens if |
The scroll view does not scroll horizontally. |
Maybe needs to also implement shouldBeRequiredToFail -> false |
No, I have already tried without success. |
Without SPM for framework edit capabilities... |
Apple's sheet presentation controller has the challenge, where if you pan in a scroll view, it has to understand if you are scrolling or not, and then if not, pull the controller's view to dismiss. I wonder what hacks they do there. |
@iDevelopper @LeoNatan the weird thing is that if there's a tableView inside the horizontally scrollView it works great (because the tableView fails as soon as it reaches the top I guess). I'm trying to replicate this on a view where no scrolling should happen, when adding a vertical scrollView it obviously doesn't work because the scrolling is ignored since there's no need to scroll. Any ideas? I've tried adding 1pt to the scrollView content at the bottom but it scrolls way more than that point |
I think things are now much better. If there are still issues with horizontal scrolling, I think I've hit the limit with the framework gesture recognizer logic, and it will be up to the developers to provide a delegate for the interaction gesture recognizer and improve this behavior. |
I have a horizontal Collection View in my View Controller that is presented by LNPopupController and I can't find a way to register dragging down the controller if the touches are in the Collection View's area. If I disable scrolling of Collection View it works great but disabling it is out of question, also subclassing UICollectionView and using UIGestureDelegate's method
gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer)
doesn't make any difference.The text was updated successfully, but these errors were encountered: