LeoNatan / LNPopupController

A framework for presenting view controllers as popups of other view controllers, much like the Apple Music and Podcasts apps.
MIT License
3.04k stars 342 forks source link

How to add action when clicking on custom LNPopupCustomBarViewController #444

Closed gorbat-o closed 3 years ago

gorbat-o commented 3 years ago

Amazing library!

I am not sure to understand how to add an action when you click on a custom LNPopupCustomBarViewController. Is there a delegate or notification i can subscribe to know when the user click on the popupController ?

iDevelopper commented 3 years ago

There is a protocol named LNPopupPresentationDelegate and a method called when the user taps on the popup bar to open the popup content view controller:

    func popupPresentationControllerWillOpenPopup(_ popupPresentationController: UIViewController, animated: Bool) {
        // ...
    }
LeoNatan commented 3 years ago

@gorbat-o Does that answer your question? LNPopupCustomBarViewController is responsible for just the custom bar presentation, you should not be performing action in it related to the popup opening or closing. For listening to the popup state in general, as @iDevelopper said, LNPopupPresentationDelegate exists that gives you updates.

gorbat-o commented 3 years ago

That should do it! I will iterate with that! thank you for the quick reply!!

gorbat-o commented 3 years ago

I am actually using the LNPopupCustomBarViewController and it doesn't seem to have access to LNPopupPresentationDelegate. Where do I acces to popupPresentationControllerWillOpenPopup.

I have found the popupOpenGestureRecognizer in LNPopupBar but can't do much with that.

I just need to add an action for when the popup is clicked that is not related to the popup itself.

LeoNatan commented 3 years ago

Did you look at the header documentation?

https://github.com/LeoNatan/LNPopupController/blob/f5987c5eb48a5bf71b7322719c0e56f14df2d01c/LNPopupController/LNPopupController/UIViewController%2BLNPopupSupport.h#L244

You set that property with the object you'd like to be the delegate. The property should be set on the popup presentation container controller (like your tab bar, etc.).

See example here: https://github.com/LeoNatan/LNPopupController/blob/1b803db790ec596b2fa576e7390d582ad69ff0d1/LNPopupControllerExample/LNPopupControllerExample/FirstViewController.m#L350

If you'd like to have your custom bar controller as the delegate, set it. I don't think it's a good decision, but it's up to you.

LeoNatan commented 3 years ago

If you just need to respond to taps on the bar, you can add your own gesture recognizer that can recognize simultaneously with the system gesture recognizer. That I think is a better option in your case.

gorbat-o commented 3 years ago

Ok yep sounds good! I thought there might be a way to use the one included! Thanks Leo and merci Patrick for your help!

gorbat-o commented 3 years ago

When I add my own tap gesture it seems to block the one from the library. I added the gesture in the viewDidLoad of my subclass of LNPopupCustomBarViewController.

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.popupBarTapped(_:)))
container.addGestureRecognizer(tapGesture)
LeoNatan commented 3 years ago

You need to learn how to use gesture recognizer.

gorbat-o commented 3 years ago

I thought I knew! 😁 Will definitely read more documentation about it Thanks for your time

gorbat-o commented 3 years ago

Thanks for the poke!

For those who will be interested. I was able to make it work by implementing func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool function from UIGestureRecognizerDelegate.

iDevelopper commented 3 years ago

@gorbat-o,

Archive.zip