SWRevealViewController gestures not working

Hi I have an embedded swrevealview controller in swift mode.

I wrote below code in delegate app.

let frontView = ViewController(nibName: "ViewController", bundle: nil)
    let rearView = LeftViewController(nibName : "LeftViewController", bundle :nil)

    var frontNavigationController = UINavigationController(rootViewController: frontView)
    var rearNavigationController = UINavigationController(rootViewController: rearView)

    menuSlider = SWRevealViewController(rearViewController: rearNavigationController, frontViewController: frontNavigationController)
    menuSlider?.delegate = self

    let rightView = LeftViewController(nibName : "RightViewController", bundle :nil)

    menuSlider?.rightViewController = rightView

    self.window?.rootViewController = menuSlider
    self.window?.backgroundColor = UIColor.whiteColor()
    self.window?.makeKeyAndVisible()

      

In the front view, I wrote

 var revealController:SWRevealViewController  = self.revealViewController()
    self.view.addGestureRecognizer(revealViewController().panGestureRecognizer())
    self.view.addGestureRecognizer(revealViewController().tapGestureRecognizer())

      

as shown in the demo. I have seen many posts suggesting to add gesture in views.

I'm not sure what I am doing wrong. Please help me with the solution.

thank

+3


source to share


2 answers


One thing I can think of is when it comes to your code, you don't store strong references to front rearview controllers anywhere. It will basically be deallocated immediately after execution exits the method body. In your case, something like this will solve the problem:

Class myClass { 

    // Declaration
    var frontNC : UINavigationController!
    var rearNC : UINavigationController!

    ...
    func myFunction() {

       // Usage
       self.frontNC = UINavigationController(rootViewController: frontView)
       self.readNC = UINavigationController(rootViewController: rearView)

       // Note* there is no need to store ViewControllers because those
       // are retained by UINavigationController by default. The only
       // exception is if you want to do something with them later obviously :)
    }
}

      



As long as it is displayed, it creates a whole bunch of problems and gesture recognizers, which are the worst to track in my experience.

You can read more details on how ARC works in the Apple documentation , I don't think anyone can explain it better than what is written there :)

0


source


Add the following method viewDidLoad

,



view.addGestureRecognizer(revealViewController().panGestureRecognizer())

      

0


source







All Articles