简体   繁体   中英

SWRevealViewController - How can I make the menu disappear with a tap and/or swipe on FrontViewController

I am developing a locator map. How can I make the menu disappear with a tap and/or swipe on FrontViewController. My front view controller displays a Map (Google Map).

You can enable the use of swipe gestures to close your menu in the SWRevealViewController by adding its pan gesture recognizer to your view in viewDidLoad: of your view controller.

override func viewDidLoad() 
{
    super.viewDidLoad()                 
    view.addGestureRecognizer(myRevealViewController.panGestureRecognizer())
}

Getting the menu to respond to taps requires handling the tap action separately with a tap gesture recognizer.

For example, with a tap gesture recognizer defined and added to your view like

myTapGestureRecognizer = UITapGestureRecognizer(target: self, action: "closeMenu")
view.addGestureRecognizer(myTapGestureRecognizer)

You could close the menu with a function using:

func closeMenu()
{      
    myRevealViewController?.setFrontViewPosition(FrontViewPosition.Left, animated: true)
}

where the .Left for FrontViewPosition is dependent on how you have your view controllers configured for your SWRevealViewController .

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