Search code examples
iosswiftgestureswrevealviewcontrollerpan

Gesture in multiple views


I have used SWRevealViewController for slide menu feature and I added a gesture recognizer so that I can see the slide menu. I succeed in this with the following lines.

detail.target = revealViewController()
detail.action = #selector(SWRevealViewController.revealToggle(_:))
view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())

detail is the bar button which also show the slide menu

Now I have 4 tabs and I want each tab to has the button and the gesture. I set up all swift files(of tabs) with the above code and it works BUT!

Here is my problem, for example: I start with the first tab I use the gesture it works; I go to the second tab the gesture also works; if I go back to first tab the gesture doesn't work!!

The button always works! (i used to all tabs copy-paste the code!)

Any help? :D


Solution

  • After your question where i put the code i realize that viewDidLoad only runs the first time so i put the code inside viewdidappear like this:

     override func viewDidAppear(animated: Bool) {
            view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
        }
    

    and everything is fine and works perfectly now :)