IGLDropDownMenu icon indicating copy to clipboard operation
IGLDropDownMenu copied to clipboard

Add UITapGesture to close menu

Open Jackson0111 opened this issue 8 years ago • 8 comments

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?

Jackson0111 avatar Mar 13 '16 05:03 Jackson0111

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.

bestwnh avatar Mar 13 '16 06:03 bestwnh

I got it! Thanks! This whole time I thought .expanding is a get only function for some reason...

Jackson0111 avatar Mar 13 '16 06:03 Jackson0111

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?

Jackson0111 avatar Mar 13 '16 06:03 Jackson0111

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?

Jackson0111 avatar Mar 13 '16 07:03 Jackson0111

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.

Jackson0111 avatar Mar 13 '16 08:03 Jackson0111

If anyone else has a better way of doing this, please share!

Jackson0111 avatar Mar 13 '16 08:03 Jackson0111

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 avatar May 11 '16 12:05 chinnuios

@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.

bestwnh avatar May 11 '16 13:05 bestwnh