I've implemented SWRevealViewController for a slide-out menu in my Swift app. One issue with this framework is that when the menu (rearView) is expanded the user can still interact with the frontView. Since my frontView is a full bleed map it's very difficult to close the menu by tapping on the frontView, because instead of recognizing it as a pan/tap to close it just moves the map around.
There is the same questions for Objective-C here. The top answer from @hardluckbaby seems to be the best solution, but it's in Objective-C. I've gotten the first part of the answer working in Swift, I need help with the second part.
In my rearView controller if added these two functions which successfully disable interactions on the frontView when the rearView (menu) is open:
override func viewWillAppear(animated: Bool) {
self.revealViewController().frontViewController.view.userInteractionEnabled = false
}
override func viewWillDisappear(animated: Bool) {
self.revealViewController().frontViewController.view.userInteractionEnabled = true
}
This final part I need help converting to Swift. It's suppose to re-enable the pan/tap gestures for my frontView. In my frontView I'm suppose to place the following in my ViewDidLoad function:
SWRevealViewController *revealController = [self revealViewController];
[revealController panGestureRecognizer];
[revealController tapGestureRecognizer];
How can this last part be written in Swift?
I tried adding it to this function, but it doesn't recognize my taps. Do I need to take it out of this IF statement?
override func viewDidLoad() {
super.viewDidLoad()
if self.revealViewController() != nil {
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
self.view.addGestureRecognizer(self.revealViewController().tapGestureRecognizer())
}
}