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

Add UITapGesture to close menu #26

Open
Jackson0111 opened this issue Mar 13, 2016 · 8 comments
Open

Add UITapGesture to close menu #26

Jackson0111 opened this issue Mar 13, 2016 · 8 comments

Comments

@Jackson0111
Copy link

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?

@bestwnh
Copy link
Owner

bestwnh commented Mar 13, 2016

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.

@Jackson0111
Copy link
Author

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

@Jackson0111
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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

@chinnuios
Copy link

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.

@bestwnh
Copy link
Owner

bestwnh commented May 11, 2016

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

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

3 participants