IGLDropDownMenu
IGLDropDownMenu copied to clipboard
Add UITapGesture to close menu
I've been trying to figure out how to close the menu when user taps somewhere on the screen. When users don't pick an option, or try to type something in a textField, I want to close the menu to keep the UI clean. How can I achieve this?
You may need to set up a view to detect the use click outside the menu when it expanding. And control the setExpanding
to close the menu.
I got it! Thanks! This whole time I thought .expanding is a get only function for some reason...
I'm still having trouble to achieve goal. When I add a tap gesture recognizer, the dropdown menu becomes disabled. Any suggestions how I can add the tap gesture outside the menu frame?
I'm trying to do this with the code below:
` func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
let point : CGPoint = touch.locationInView(self.view)
let pointInSubview : CGPoint = self.view.convertPoint(point, fromView: self.view)
if !CGRectContainsPoint(self.categoryMenu.frame, pointInSubview) {
print("tapped outside category menu")
// self.view.removeGestureRecognizer(dropDownMenuTap)
// return false
}else {
print("tapped inside category menu")
}
self.view.removeGestureRecognizer(dropDownMenuTap)
return true
}`
I have 6 options in categoryMenu, the output is all correct except when I tap on the last two columns in the menu, which is super weird, any thoughts maybe?
Alright, I finally solved it with this https://gist.github.com/sburlot/9856a15119985a6f1a87 kind of code. I couldn't figure out why the menu's frame was wrong when touch is detected, so i just manually added 85 to its height to make it longer.
If anyone else has a better way of doing this, please share!
HI i am working with this app but i am unable to show the Drop down. I am using storyboard how can i show when i click on button.
@chinnuios This is different issue, please create another issue for your question. And it's better to provide more detail and code about how you use it.