John-Lluch / SWRevealViewController

A UIViewController subclass for presenting side view controllers inspired on the FaceBook and Wunderlist apps, done right !
Other
4.52k stars 987 forks source link

Close revealviewcontroller when tapped on the page #821

Open mustafashaheen1 opened 4 years ago

mustafashaheen1 commented 4 years ago

I am using swift and xocde 12. And I am using TableViewController for the menu. I have tried following solutions but they didn't work.

`override func touchesBegan(_ touches: Set, with event: UIEvent?) { if let touch = touches.first { if self.revealViewController() != nil { self.view.addGestureRecognizer(self.revealViewController().tapGestureRecognizer()) } }

    super.touchesBegan(touches , with:event)
}`

`if self.revealViewController() != nil {

    self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
    self.view.addGestureRecognizer(self.revealViewController().tapGestureRecognizer())
}`
iDevelopper commented 4 years ago

Override touchesBegan is not needed! addGestureRecognizer is not needed!

Reading the documentation in the .h file: Just do it in the viewDidLoad of your main view controller:

class MainViewController: UITabBarController, SWRevealViewControllerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.revealViewController().tapGestureRecognizer()
        self.revealViewController().panGestureRecognizer()
        // ...

And the rear view will be closed automatically.

mustafashaheen1 commented 4 years ago

I just tried this didn't work. I have a UINavigationController as front not UITabBarController and TableViewController as rear

iDevelopper commented 4 years ago

It was an example. Just call revealViewController().tapGestureRecognizer in your main view controller.

mustafashaheen1 commented 4 years ago

I actually did that but still doesn't work. Just one thing the front page the whole view is google map where user taps. Can that be an issue? Here is my current code:

`import UIKit import SWRevealViewController class HomePageNavigationViewController: UINavigationController , SWRevealViewControllerDelegate{

override func viewDidLoad() {
    super.viewDidLoad()
    self.revealViewController().tapGestureRecognizer()
    self.revealViewController().panGestureRecognizer()
    // Do any additional setup after loading the view.
}`