简体   繁体   中英

Swift 3 multiple gestureRecorgnizer SWRevealController

I have two gestureRecognizer I want to use.

1) Tap to close side menu (SWRevealController)

2) Tap view to dismiss keyboard

    override func viewDidLoad() {
    super.viewDidLoad()
    menuBtn.addTarget(self.revealViewController(), action: #selector(SWRevealViewController.revealToggle(_:)), for: .touchUpInside)
    self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
    self.view.addGestureRecognizer(self.revealViewController().tapGestureRecognizer())
    let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(LoginController.dismissKeyboard))
    self.view.addGestureRecognizer(tap)
    }

Having both of these lines together, the dismiss keyboard gestureRecognizer trumps the revealViewController. How can I combine this this use both gestures together?

Make condition in LoginController.dismissKeyboard method.
check if isKeyboard is open, then close it. Otherwise close the (SWRevealController) sidemenu.

For check keyboard is open or not you can use post notification of UIKeyboardWillShowNotification and UIKeyboardWillHideNotification methods.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM