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

Adding gesture recognizer to backdropView does not work #99

Closed
fmessina opened this issue Jan 7, 2019 · 7 comments
Closed

Adding gesture recognizer to backdropView does not work #99

fmessina opened this issue Jan 7, 2019 · 7 comments

Comments

@fmessina
Copy link

fmessina commented Jan 7, 2019

Hi and thanks for the library :)

I've been trying to add a gesture recognizer to the backdropView to dismiss the panel, but I can't get it to work. It's like if the selector attached to the gesture never gets called.

I'm on the last version.

This is how I do it (as described here https://github.com/SCENEE/FloatingPanel#add-tap-gestures-to-the-surface-or-backdrop-views)

let backdropTapGesture = UITapGestureRecognizer(target: self, action: #selector(self.handleBackdropTapGesture(_:)))
self.floatingPanelController.backdropView.addGestureRecognizer(backdropTapGesture)

and

@objc private func handleBackdropTapGesture(_ gesture: UITapGestureRecognizer) {
     // Never gets called
     print("DISMISS")
}

If I add the tapGesture on the surfaceView everything works.
Any idea?
Thanks!

@scenee
Copy link
Owner

scenee commented Jan 8, 2019

Hello, @fmessina! Thanks for your usage!

I'm sorry I can't reproduce this issue. On Samples app, a tap gesture recognizer added into backdropView is working well. https://github.com/SCENEE/FloatingPanel/blob/master/Examples/Samples/Sources/ViewController.swift#L150

But If a backdropView's alpha is zero, a tap gesture recognizer of it doesn't work by design.

@fmessina
Copy link
Author

fmessina commented Jan 8, 2019 via email

@fmessina
Copy link
Author

fmessina commented Jan 8, 2019

I ended up with this solution:

In my FloatingPanelLayout delegate:

    func backdropAlphaFor(position: FloatingPanelPosition) -> CGFloat {
        return position == .half ? 0.05 : 0.0
    }

This way I have an almost invisible alpha on the backdropView and the dismiss on touch (the one provided by the library) works well.

Looks a bit like an hack but it works :)

@scenee
Copy link
Owner

scenee commented Jan 9, 2019

Let me confirm your background. Do you present a floating panel view controller modally?

@scenee
Copy link
Owner

scenee commented Jan 9, 2019

I'm sorry I found an unexpected behavior if a floating panel controller is presented modally.

The controller should not block any touch events if the backdrop view's alpha is zero because it seems to able to touch views behind the backdrop view. I made a fix-touch-handling-on-presentation-modally branch on which I fixed it to pass through touch events to the views managed by the presenting view controller.

My original expectation is different from yours. What do you think of the expectation?

@fmessina
Copy link
Author

fmessina commented Jan 9, 2019

I think your expectation is correct too.

What I wanted is to tap outside to dismiss it, so maybe if the alpha is zero the tap gesture should go on the presenting view controller.

Thanks for the fix, I will pull it when it will be released.

@scenee
Copy link
Owner

scenee commented Jan 9, 2019

Thank you for your confirmation! I merged the branch to the master. I will release v1.3.2 soon.

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

2 participants