SWRevealViewController icon indicating copy to clipboard operation
SWRevealViewController copied to clipboard

Close revealviewcontroller when tapped on the page

Open mustafashaheen1 opened this issue 4 years ago • 4 comments

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<UITouch>, 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())
}`

mustafashaheen1 avatar Oct 05 '20 07:10 mustafashaheen1

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.

iDevelopper avatar Oct 05 '20 10:10 iDevelopper

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

mustafashaheen1 avatar Oct 05 '20 11:10 mustafashaheen1

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

iDevelopper avatar Oct 05 '20 12:10 iDevelopper

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.
}`

mustafashaheen1 avatar Oct 05 '20 18:10 mustafashaheen1